From 05ed69880b17316195d7dc84e960363158c73ba4 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Wed, 2 Sep 2015 16:19:09 +0200 Subject: [PATCH 1/3] [ADD] web_menu_navbar_needaction --- web_menu_navbar_needaction/README.rst | 55 ++++++++++++ web_menu_navbar_needaction/__init__.py | 20 +++++ web_menu_navbar_needaction/__openerp__.py | 37 +++++++++ .../data/ir_config_parameter.xml | 9 ++ web_menu_navbar_needaction/models/__init__.py | 20 +++++ .../models/ir_ui_menu.py | 36 ++++++++ .../static/description/icon.png | Bin 0 -> 1140 bytes .../src/css/web_menu_navbar_needaction.css | 4 + .../src/js/web_menu_navbar_needaction.js | 78 ++++++++++++++++++ web_menu_navbar_needaction/tests/__init__.py | 20 +++++ .../tests/test_web_menu_navbar_needaction.py | 27 ++++++ .../views/templates.xml | 11 +++ 12 files changed, 317 insertions(+) create mode 100644 web_menu_navbar_needaction/README.rst create mode 100644 web_menu_navbar_needaction/__init__.py create mode 100644 web_menu_navbar_needaction/__openerp__.py create mode 100644 web_menu_navbar_needaction/data/ir_config_parameter.xml create mode 100644 web_menu_navbar_needaction/models/__init__.py create mode 100644 web_menu_navbar_needaction/models/ir_ui_menu.py create mode 100644 web_menu_navbar_needaction/static/description/icon.png create mode 100644 web_menu_navbar_needaction/static/src/css/web_menu_navbar_needaction.css create mode 100644 web_menu_navbar_needaction/static/src/js/web_menu_navbar_needaction.js create mode 100644 web_menu_navbar_needaction/tests/__init__.py create mode 100644 web_menu_navbar_needaction/tests/test_web_menu_navbar_needaction.py create mode 100644 web_menu_navbar_needaction/views/templates.xml diff --git a/web_menu_navbar_needaction/README.rst b/web_menu_navbar_needaction/README.rst new file mode 100644 index 00000000..b9e2428e --- /dev/null +++ b/web_menu_navbar_needaction/README.rst @@ -0,0 +1,55 @@ +.. 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 required 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. + +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..a570babe --- /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": "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 0000000000000000000000000000000000000000..2ee261b9ab7887bd581c260a5705e5f762530cb9 GIT binary patch literal 1140 zcmV-)1dIELP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00Z1fL_t(|+U?mrNNQmi2k^gn z%t0d$VGT*2TOnoQ88R~xLR_q-D2N(r427U5s2~E@2%NM@+5*8K=yP&P%s`7EGtgQR zG{VKKd#Aj5EAPp=-jALixcHps<(xmSp7Xv3AcPP?2qAcw zP2VVn;+0VZ6d(mi0aAdZSj_);QF6IF`;p0HC@(M1*3#)TlF1})Z*Q|7dW?CV4GaT~ zMgxUH!Mi6Gi{a?#2$@XgYtO*S%1UUpT1X_4cl9Y03a~5-uh)yaySuOXAILCFQQl|wO|2yg0EJUqVBNmH6AP{`Yc%KrW zNF+iu8imnl%==!i*CQT}=RGzUjYjP6@8j(34BOk=;5aT@YiMY|?(Qy*kB>1hFn~}f z#H)|*1q%cM=yW>xe7?UcKmc<(DRyC@cFhgw<+=%jL>DZh3hb7K;T+r4n|#9rN?^ z+1lLP9JaQ$(B0h)l}ZJ%Sj?+07t6A5o?}Z(3&dhE&d<+zUzbcKD@}lxmzRh}qZk|< z1OS*!CdA`$TwGk_9T$(sVKf?1U0n^2#{;w3oUL_qbin0u;r{*}>+9=zv!qZTUwXYB ze!rjB|6lH`E!kbz;c#GTY6@bp7*?wl4u|8#F%uILU|AM!w;LXh2O5ngTdSz3Kr)#G z0NmW%@b1f%NF?4ozq-0Q==J)%yRXe=gH$Sgv!~E_pSBVShr?)YZUz9j-EN$moS?0( z4gLN7FY39>W;3Rzr?Yo(zu%AE-d-e=Nz~WZ$OxQH=d1P2%}tn0CNK{yVs;VmN?d?IOQWdq7>+9<)dMO70sZ. +// +// 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 @@ + + + + + + From 1dfd8c5f1fe5ad506fd99768ca1a27335772fe64 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 4 Sep 2015 08:01:32 +0200 Subject: [PATCH 2/3] [FIX] manifest & readme --- web_menu_navbar_needaction/README.rst | 1 + web_menu_navbar_needaction/__openerp__.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/web_menu_navbar_needaction/README.rst b/web_menu_navbar_needaction/README.rst index b9e2428e..335a3ed0 100644 --- a/web_menu_navbar_needaction/README.rst +++ b/web_menu_navbar_needaction/README.rst @@ -1,5 +1,6 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg :alt: License: AGPL-3 +================================ Needaction counters in main menu ================================ diff --git a/web_menu_navbar_needaction/__openerp__.py b/web_menu_navbar_needaction/__openerp__.py index a570babe..e1356e9c 100644 --- a/web_menu_navbar_needaction/__openerp__.py +++ b/web_menu_navbar_needaction/__openerp__.py @@ -19,7 +19,7 @@ ############################################################################## { "name": "Needaction counters in main menu", - "version": "1.0.0", + "version": "8.0.1.0.0", "author": "Therp BV,Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Usability", From ec1d2a706a4ef5f8beee9106ebf5929520c70415 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 4 Sep 2015 08:03:53 +0200 Subject: [PATCH 3/3] [FIX] typo --- web_menu_navbar_needaction/README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web_menu_navbar_needaction/README.rst b/web_menu_navbar_needaction/README.rst index 335a3ed0..81d54813 100644 --- a/web_menu_navbar_needaction/README.rst +++ b/web_menu_navbar_needaction/README.rst @@ -6,13 +6,15 @@ 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 required attention. +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 =====