From ffe13756f5717088dbe13f042a92ae0ea8ba2a73 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 11 Jan 2017 10:54:05 +0100 Subject: [PATCH] [FIX] mrp: manufacturing vignette in inventory dashboard When clicking on the "manufacturing" vignette in the inventory dashboard, the records were not filtered correctly (example: add a new warehouse, a new "manufacturing" vignette appears for this warehouse in the inventory dashboard, clicking on it would display the MO of all the warehouses). With this fix, as with the pickings, it will only show the count of MO filtered to that specific picking type in the vignette, and clicking on it will displayed the filtered ones. We implementent the method of the compute field the same way the similar method for the picking is implemented. fixes #15008 --- addons/mrp/models/stock_picking.py | 21 ++++++++++++--------- addons/mrp/views/mrp_production_views.xml | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/addons/mrp/models/stock_picking.py b/addons/mrp/models/stock_picking.py index 90e7574185f..7955caf0722 100644 --- a/addons/mrp/models/stock_picking.py +++ b/addons/mrp/models/stock_picking.py @@ -16,12 +16,15 @@ class StockPickingType(models.Model): mrp_picking_types = self.filtered(lambda picking: picking.code == 'mrp_operation') if not mrp_picking_types: return - - MrpProduction = self.env['mrp.production'] - count_mo_waiting = MrpProduction.search_count([('availability', '=', 'waiting')]) - count_mo_todo = MrpProduction.search_count([('state', 'in', ('confirmed', 'planned', 'progress'))]) - count_mo_late = MrpProduction.search_count(['&', ('date_planned_start', '<', fields.Date.today()), ('state', '=', 'confirmed')]) - for picking in mrp_picking_types: - picking.count_mo_waiting = count_mo_waiting - picking.count_mo_todo = count_mo_todo - picking.count_mo_late = count_mo_late + domains = { + 'count_mo_waiting': [('availability', '=', 'waiting')], + 'count_mo_todo': [('state', 'in', ('confirmed', 'planned', 'progress'))], + 'count_mo_late': [('date_planned_start', '<', fields.Date.today()), ('state', '=', 'confirmed')], + } + for field in domains: + data = self.env['mrp.production'].read_group(domains[field] + + [('state', 'not in', ('done', 'cancel')), ('picking_type_id', 'in', self.ids)], + ['picking_type_id'], ['picking_type_id']) + count = dict(map(lambda x: (x['picking_type_id'] and x['picking_type_id'][0], x['picking_type_id_count']), data)) + for record in mrp_picking_types: + record[field] = count.get(record.id, 0) \ No newline at end of file diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index 456d10e1427..2d30efd1aff 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -307,7 +307,8 @@ tree,form - {} + [('picking_type_id', '=', active_id)] + {'default_picking_type_id': active_id}