From eba01d5753852d2a5672ec02cb593995868507da Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 20 Oct 2015 13:33:24 +0200 Subject: [PATCH] [FIX] count needactions from the same model only once --- web_menu_navbar_needaction/models/ir_ui_menu.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/web_menu_navbar_needaction/models/ir_ui_menu.py b/web_menu_navbar_needaction/models/ir_ui_menu.py index 052446ad..8cc1b553 100644 --- a/web_menu_navbar_needaction/models/ir_ui_menu.py +++ b/web_menu_navbar_needaction/models/ir_ui_menu.py @@ -27,10 +27,15 @@ class IrUiMenu(models.Model): 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()) - ) + count_per_model = {} + for menu_id, needaction in self.search( + [('id', 'child_of', this.ids)])._filter_visible_menus()\ + .get_needaction_data().iteritems(): + if needaction['needaction_enabled']: + model = self.env['ir.ui.menu'].browse(menu_id).action\ + .res_model + count_per_model[model] = max( + count_per_model.get(model), + needaction['needaction_counter']) + result[this.id] = sum(count_per_model.itervalues()) return result