From ecdf96e8a7b148c74b8d6fe045e3961be981831b Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 28 Jun 2017 12:10:46 +0200 Subject: [PATCH] [FIX] mrp, stock: Traceability of MO disappears when product returned after delivery Steps to reproduce: Let's consider product P tracked by serial number P has a manufacture BOM B with Q as componenent - Produce P with serial number SN(with MO) - Send P with SN to a customer A(with SO and DO) - Force availability on P to a customer B(with SO and DO) - Return P to stock for customer A. Bug: The tracability for P removed the component Q(consumed_quant_ids) when reconciling the negative quant(generated for B) with the returned quant from A. opw:744424 --- addons/mrp/models/stock_quant.py | 6 ++++++ addons/stock/models/stock_quant.py | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/stock_quant.py b/addons/mrp/models/stock_quant.py index e94b786f568..6074735a737 100644 --- a/addons/mrp/models/stock_quant.py +++ b/addons/mrp/models/stock_quant.py @@ -11,3 +11,9 @@ class StockQuant(models.Model): 'stock.quant', 'stock_quant_consume_rel', 'produce_quant_id', 'consume_quant_id') produced_quant_ids = fields.Many2many( 'stock.quant', 'stock_quant_consume_rel', 'consume_quant_id', 'produce_quant_id') + + def _prepare_history(self): + vals = super(StockQuant, self)._prepare_history() + vals['consumed_quant_ids'] = [(4, quant.id) for quant in self.consumed_quant_ids] + vals['produced_quant_ids'] = [(4, quant.id) for quant in self.produced_quant_ids] + return vals diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index de4cf2b5fa6..1c11ad0c99f 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -334,12 +334,15 @@ class Quant(models.Model): # price update + accounting entries adjustments solved_quants._price_update(solving_quant.cost) # merge history (and cost?) - solved_quants.write({ - 'history_ids': [(4, history_move.id) for history_move in solving_quant.history_ids] - }) + solved_quants.write(solving_quant._prepare_history()) solving_quant.with_context(force_unlink=True).unlink() solving_quant = remaining_solving_quant + def _prepare_history(self): + return { + 'history_ids': [(4, history_move.id) for history_move in self.history_ids], + } + @api.multi def _price_update(self, newprice): # TDE note: use ACLs instead of sudoing everything