diff --git a/web_menu_navbar_needaction/README.rst b/web_menu_navbar_needaction/README.rst new file mode 100644 index 00000000..81d54813 --- /dev/null +++ b/web_menu_navbar_needaction/README.rst @@ -0,0 +1,58 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 +================================ +Needaction counters in main menu +================================ + +This module shows the sum of all submenus' needaction counters in main menus. This way, users get visual feedback where there's still work to do without having to open the respective menu beforehand. + +The counters are updated periodically, so users will also be notified if there are new records that require attention. + +Configuration +============= + +To configure the update frequency, set the configuration parameter `web_menu_navbar_needaction.refresh_timeout` to the amount of milliseconds after which the counters should be updated. Don't do this too often, as this will cause a lot of queries to the database. The default it 600000, which is equivalent to 10 minutes. + +To disable updates, set the parameter to 0. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/8.0 + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/web_menu_navbar_needaction/__init__.py b/web_menu_navbar_needaction/__init__.py new file mode 100644 index 00000000..cdb7d736 --- /dev/null +++ b/web_menu_navbar_needaction/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import models diff --git a/web_menu_navbar_needaction/__openerp__.py b/web_menu_navbar_needaction/__openerp__.py new file mode 100644 index 00000000..e1356e9c --- /dev/null +++ b/web_menu_navbar_needaction/__openerp__.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "Needaction counters in main menu", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Usability", + "summary": "Show the sum of submenus' needaction counters in main menu", + "depends": [ + 'web', + ], + "data": [ + "data/ir_config_parameter.xml", + 'views/templates.xml', + ], + "auto_install": False, + "installable": True, + "application": False, +} diff --git a/web_menu_navbar_needaction/data/ir_config_parameter.xml b/web_menu_navbar_needaction/data/ir_config_parameter.xml new file mode 100644 index 00000000..757fd1b8 --- /dev/null +++ b/web_menu_navbar_needaction/data/ir_config_parameter.xml @@ -0,0 +1,9 @@ + + + + + web_menu_navbar_needaction.refresh_timeout + 600000 + + + diff --git a/web_menu_navbar_needaction/models/__init__.py b/web_menu_navbar_needaction/models/__init__.py new file mode 100644 index 00000000..66a84b35 --- /dev/null +++ b/web_menu_navbar_needaction/models/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import ir_ui_menu diff --git a/web_menu_navbar_needaction/models/ir_ui_menu.py b/web_menu_navbar_needaction/models/ir_ui_menu.py new file mode 100644 index 00000000..052446ad --- /dev/null +++ b/web_menu_navbar_needaction/models/ir_ui_menu.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp import models, api + + +class IrUiMenu(models.Model): + _inherit = 'ir.ui.menu' + + @api.multi + def get_navbar_needaction_data(self): + result = {} + for this in self: + result[this.id] = sum(map( + lambda x: x['needaction_counter'], + self.search([('id', 'child_of', this.ids)]) + ._filter_visible_menus().get_needaction_data() + .itervalues()) + ) + return result diff --git a/web_menu_navbar_needaction/static/description/icon.png b/web_menu_navbar_needaction/static/description/icon.png new file mode 100644 index 00000000..2ee261b9 Binary files /dev/null and b/web_menu_navbar_needaction/static/description/icon.png differ diff --git a/web_menu_navbar_needaction/static/src/css/web_menu_navbar_needaction.css b/web_menu_navbar_needaction/static/src/css/web_menu_navbar_needaction.css new file mode 100644 index 00000000..259502de --- /dev/null +++ b/web_menu_navbar_needaction/static/src/css/web_menu_navbar_needaction.css @@ -0,0 +1,4 @@ +#oe_main_menu_navbar .badge +{ + margin-left: .3em; +} diff --git a/web_menu_navbar_needaction/static/src/js/web_menu_navbar_needaction.js b/web_menu_navbar_needaction/static/src/js/web_menu_navbar_needaction.js new file mode 100644 index 00000000..93a859ad --- /dev/null +++ b/web_menu_navbar_needaction/static/src/js/web_menu_navbar_needaction.js @@ -0,0 +1,78 @@ +//-*- coding: utf-8 -*- +//############################################################################ +// +// This module copyright (C) 2015 Therp BV . +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +//############################################################################ + +openerp.web_menu_navbar_needaction = function(instance) +{ + instance.web.Menu.include({ + init: function() + { + var self = this, + result = this._super.apply(this, arguments); + this.on('menu_bound', this, function() + { + new instance.web.Model('ir.config_parameter') + .call('get_param', + ['web_menu_navbar_needaction.refresh_timeout']) + .then(self.proxy(self.refresh_navbar_needaction)) + }); + return result; + }, + refresh_navbar_needaction: function(timeout) + { + if(timeout) + { + setTimeout(this.proxy(this.refresh_navbar_needaction), timeout, timeout); + } + return this.load_navbar_needaction(); + }, + load_navbar_needaction: function() + { + this.navbar_menu_ids = this.$el.parents('body') + .find('#oe_main_menu_navbar a[data-menu]') + .filter(function() { return parseInt(jQuery(this).attr('data-menu')); }) + .map(function() { return parseInt(jQuery(this).attr('data-menu')); }) + .get(); + return new instance.web.Model('ir.ui.menu') + .call('get_navbar_needaction_data', [this.navbar_menu_ids]) + .then(this.proxy(this.process_navbar_needaction)); + }, + process_navbar_needaction: function(data) + { + var self = this; + _.each(data, function (needaction_count, menu_id) + { + var $item = self.$el.parents('body').find( + _.str.sprintf('#oe_main_menu_navbar a[data-menu="%s"]', + menu_id)); + if(!$item.length) + { + return; + } + $item.find('.badge').remove(); + if(needaction_count) + { + $item.append( + instance.web.qweb.render("Menu.needaction_counter", + {widget : {needaction_counter: needaction_count}})); + } + }); + }, + }) +} diff --git a/web_menu_navbar_needaction/tests/__init__.py b/web_menu_navbar_needaction/tests/__init__.py new file mode 100644 index 00000000..b5806ddf --- /dev/null +++ b/web_menu_navbar_needaction/tests/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import test_web_menu_navbar_needaction diff --git a/web_menu_navbar_needaction/tests/test_web_menu_navbar_needaction.py b/web_menu_navbar_needaction/tests/test_web_menu_navbar_needaction.py new file mode 100644 index 00000000..a0fd17c0 --- /dev/null +++ b/web_menu_navbar_needaction/tests/test_web_menu_navbar_needaction.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp.tests.common import TransactionCase + + +class TestWebMenuNavbarNeedaction(TransactionCase): + def test_web_menu_navbar_needaction(self): + main_menus = self.env['ir.ui.menu'].search([('parent_id', '=', False)]) + data = main_menus.get_navbar_needaction_data() + self.assertEqual(len(main_menus), len(data)) diff --git a/web_menu_navbar_needaction/views/templates.xml b/web_menu_navbar_needaction/views/templates.xml new file mode 100644 index 00000000..0f23eddd --- /dev/null +++ b/web_menu_navbar_needaction/views/templates.xml @@ -0,0 +1,11 @@ + + + + + +