From 1fac19951747078fe92e2e35c61df2372fd90eda Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 21 Mar 2019 14:06:15 +0000 Subject: [PATCH] [FIX] mrp: tracability on extra move line Usecase to reproduce: - BoM with final product tracked by SN - Produce wizard add a component tracked by SN (not from BoM) - Produce and mark the MO as done The tracability report do not show the extra component used. It happens because _record_production call _action_done on moves raw and finished. _action_done create extra move with moves that created more than expected (the purpose is to trigger rules). However in stock the new move is created then merged in its parent but in mrp moves are not merge. _record production set the tracability for initial moves but ignore the extra moves created. So the tracability report is not complete. Fix it by catching the new moves created after _action_done and set the consume_line_ids for the extra moves also. --- addons/mrp/models/mrp_production.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index ad776b6cfb0..2962fbd4fa2 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -816,11 +816,13 @@ class MrpProduction(models.Model): moves_to_do = order.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel')) for move in moves_to_do.filtered(lambda m: m.product_qty == 0.0 and m.quantity_done > 0): move.product_uom_qty = move.quantity_done - moves_to_do._action_done() + # MRP do not merge move, catch the result of _action_done in order + # to get extra moves. + moves_to_do = moves_to_do._action_done() moves_to_do = order.move_raw_ids.filtered(lambda x: x.state == 'done') - moves_not_to_do order._cal_price(moves_to_do) moves_to_finish = order.move_finished_ids.filtered(lambda x: x.state not in ('done', 'cancel')) - moves_to_finish._action_done() + moves_to_finish = moves_to_finish._action_done() order.action_assign() consume_move_lines = moves_to_do.mapped('move_line_ids') for moveline in moves_to_finish.mapped('move_line_ids'):