From d6d27e377759be14bc8500611ab84ced9182d85a Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Tue, 3 Jul 2018 11:39:29 +0200 Subject: [PATCH] [IMP] mrp: picking_type_id on stock.moves No picking_type_id is set on move created in Manufacturing orders, so when you sort/group by your all your moves in a tree view, you cannot easily identify the ones that belong to Manufacturing orders. So we've added the picking_type_id of the MO on the moves, but also had to addapt the condition to know which move having a picking_type_id and no picking must be assigned to a picking. opw:1863591 --- addons/mrp/models/mrp_production.py | 2 ++ addons/mrp/models/stock_move.py | 4 +++- addons/stock/models/stock_move.py | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 993766ebec7..73c9790a25a 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -393,6 +393,7 @@ class MrpProduction(models.Model): 'name': self.name, 'date': self.date_planned_start, 'date_expected': self.date_planned_start, + 'picking_type_id': self.picking_type_id.id, 'product_id': self.product_id.id, 'product_uom': self.product_uom_id.id, 'product_uom_qty': self.product_qty, @@ -439,6 +440,7 @@ class MrpProduction(models.Model): 'date': self.date_planned_start, 'date_expected': self.date_planned_start, 'bom_line_id': bom_line.id, + 'picking_type_id': self.picking_type_id.id, 'product_id': bom_line.product_id.id, 'product_uom_qty': quantity, 'product_uom': bom_line.product_uom_id.id, diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 3980dab4b3f..b76a77ccc44 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -262,4 +262,6 @@ class StockMove(models.Model): else: return super(StockMove, self)._get_upstream_documents_and_responsibles(visited) - + def _should_be_assigned(self): + res = super(StockMove, self)._should_be_assigned() + return bool(res and not (self.production_id or self.raw_material_production_id)) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 9758f356375..e6fc2209231 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -731,6 +731,10 @@ class StockMove(models.Model): 'location_dest_id': self.location_dest_id.id, } + def _should_be_assigned(self): + self.ensure_one() + return bool(not self.picking_id and self.picking_type_id) + def _action_confirm(self, merge=True, merge_into=False): """ Confirms stock move or put it in waiting if it's linked to another move. :param: merge: According to this boolean, a newly confirmed move will be merged @@ -750,7 +754,7 @@ class StockMove(models.Model): move_create_proc |= move else: move_to_confirm |= move - if not move.picking_id and move.picking_type_id: + if move._should_be_assigned(): key = (move.group_id.id, move.location_id.id, move.location_dest_id.id) if key not in to_assign: to_assign[key] = self.env['stock.move']