diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index ad5dd21d0d8..99cd6711d33 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1034,6 +1034,10 @@ class Menu(openerpweb.Controller): def load(self, req): return {'data': self.do_load(req)} + @openerpweb.jsonrequest + def load_needaction(self, req, menu_ids): + return {'data': self.do_load_needaction(req, menu_ids)} + @openerpweb.jsonrequest def get_user_roots(self, req): return self.do_get_user_roots(req) @@ -1071,13 +1075,13 @@ class Menu(openerpweb.Controller): context = req.session.eval_context(req.context) Menus = req.session.model('ir.ui.menu') - menu_roots = Menus.read(self.do_get_user_roots(req), ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled', 'needaction_counter'], context) - menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, ''], 'children' : menu_roots} + menu_roots = Menus.read(self.do_get_user_roots(req), ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled'], context) + menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, ''], 'children': menu_roots} # menus are loaded fully unlike a regular tree view, cause there are a # limited number of items (752 when all 6.1 addons are installed) menu_ids = Menus.search([], 0, False, False, context) - menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled', 'needaction_counter'], context) + menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled'], context) # adds roots at the end of the sequence, so that they will overwrite # equivalent menu items from full menu read when put into id:item # mapping, resulting in children being correctly set on the roots. @@ -1101,6 +1105,23 @@ class Menu(openerpweb.Controller): return menu_root + def do_load_needaction(self, req, menu_ids=False): + """ Loads needaction counters for all or some specific menu ids. + + :param req: A request object, with an OpenERP session attribute + :type req: < session -> OpenERPSession > + :return: the menu root + :rtype: dict('children': menu_nodes) + """ + context = req.session.eval_context(req.context) + Menus = req.session.model('ir.ui.menu') + + if menu_ids == False: + menu_ids = Menus.search([('needaction_enabled', '=', True)], context=context) + + menu_needaction_data = Menus.get_needaction_data(menu_ids, context) + return menu_needaction_data + @openerpweb.jsonrequest def action(self, req, menu_id): actions = load_actions_from_ir_values(req,'action', 'tree_but_open', diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 1bca6bf94cd..c1a506fd107 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -835,6 +835,21 @@ instance.web.Menu = instance.web.Widget.extend({ } this.trigger('menu_loaded', data); this.has_been_loaded.resolve(); + // Now launch the fetch of needaction counters, asynchronous + this.rpc("web/menu/load_needaction", {menu_ids: false}).done(function(r) { + self.on_needaction_loaded(r); + }); + }, + on_needaction_loaded: function(data) { + var self = this; + this.needaction_data = data; + _.each(this.needaction_data.data, function (item, menu_id) { + var $item = self.$secondary_menus.find('a[data-menu="' + menu_id + '"]'); + $item.remove('oe_menu_counter'); + if (item.needaction_counter && item.needaction_counter > 0) { + $item.append('
' + item.needaction_counter + '
'); + } + }); }, limit_entries: function() { var maximum_visible_links = this.maximum_visible_links; diff --git a/addons/web/tests/test_menu.py b/addons/web/tests/test_menu.py index c5e1b948b67..5e1d61708e1 100644 --- a/addons/web/tests/test_menu.py +++ b/addons/web/tests/test_menu.py @@ -43,7 +43,7 @@ class LoadTest(unittest2.TestCase): [], 0, False, False, self.request.session.eval_context()) self.MockMenus.read.assert_called_with( [], ['name', 'sequence', 'parent_id', - 'action', 'needaction_enabled', 'needaction_counter'], + 'action', 'needaction_enabled'], self.request.session.eval_context()) self.assertListEqual( @@ -62,7 +62,7 @@ class LoadTest(unittest2.TestCase): self.MockMenus.read.assert_called_with( [1, 2, 3], ['name', 'sequence', 'parent_id', - 'action', 'needaction_enabled', 'needaction_counter'], + 'action', 'needaction_enabled'], self.request.session.eval_context()) self.assertEqual(