From 403c6878694248731e1497b50299b2e105b4e5c4 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Mon, 7 Sep 2020 14:30:43 +0000 Subject: [PATCH] [FIX] mrp_subcontracting: Error Message with partial delivery Steps to reproduce: - Create a product P with route 'Resupply subcontractor on an order' - Let's consider a BOM for P with type 'Subcontracting' - Create a PO with subcontractor set on that product and process with Qty > 1, - Validate a receipt with partial Qty and no backorder Bug: An error was raised because no production_id was set when trying to create a mrp.product.produce When function _action_done is called with cancel_backorder = True, the function _action_cancel is called on the new_move with no backorder and it called the function _action_cancel defined on model stock.move in module mrp_subcontracting This function called _action_cancel on the mrp.production record MP And finally this function called action_cancel on model stock.move on all finish_moves and raw_moves of MP This line unlink MP of finish_moves and raw_moves move.move_dest_ids.write({'move_orig_ids': [(3, move.id, 0)]}) That's why production_id was not set PS: In this way, we don't cancel a MO when it is still used by other moves. opw:2322278 closes odoo/odoo#57346 X-original-commit: e4d22d390c8aa8edf757e36704a9e04b2b89f115 Signed-off-by: Simon Goffin (sig) --- addons/mrp_subcontracting/models/stock_move.py | 5 ++++- addons/stock/models/stock_move.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/mrp_subcontracting/models/stock_move.py b/addons/mrp_subcontracting/models/stock_move.py index 6854e8f0bff..32817a4ca8b 100644 --- a/addons/mrp_subcontracting/models/stock_move.py +++ b/addons/mrp_subcontracting/models/stock_move.py @@ -97,7 +97,10 @@ class StockMove(models.Model): def _action_cancel(self): for move in self: if move.is_subcontract: - move.move_orig_ids.production_id._action_cancel() + production = move.move_orig_ids.production_id + moves = self.env.context.get('moves_todo') + if not moves or production not in moves.move_orig_ids.production_id: + production._action_cancel() return super()._action_cancel() def _action_confirm(self, merge=True, merge_into=False): diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 98633a4f0c0..f4e08b05303 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1491,7 +1491,7 @@ class StockMove(models.Model): new_move = move._split(qty_split) move._unreserve_initial_demand(new_move) if cancel_backorder: - self.env['stock.move'].browse(new_move)._action_cancel() + self.env['stock.move'].browse(new_move).with_context(moves_todo=moves_todo)._action_cancel() moves_todo.mapped('move_line_ids').sorted()._action_done() # Check the consistency of the result packages; there should be an unique location across # the contained quants.