From 9c4c51f4176804998aec7758797eb2e24920f5bc Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Mon, 20 Nov 2017 17:41:51 +0100 Subject: [PATCH] [FIX] mrp: handle by_products When creating by products during a workorder the move lines for the final moves are not created and the user has to manually create them on the manufacturing order view. This commit adds an automatic action in order to create the correct move lines with the consumed quantity for the by products not tracked by lot or SN. This commit also fixes a bug where the consumed move lines where not linked to the by products move lines --- addons/mrp/models/mrp_production.py | 2 +- addons/mrp/models/mrp_workorder.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 4d5bb5a3f8c..cd399d60f67 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -549,7 +549,7 @@ class MrpProduction(models.Model): #order.action_assign() consume_move_lines = moves_to_do.mapped('active_move_line_ids') for moveline in moves_to_finish.mapped('active_move_line_ids'): - if moveline.move_id.has_tracking != 'none': + if moveline.product_id == order.product_id and moveline.move_id.has_tracking != 'none': if any([not ml.lot_produced_id for ml in consume_move_lines]): raise UserError(_('You can not consume without telling for which lot you consumed it')) # Link all movelines in the consumed with same lot_produced_id false or the correct lot_produced_id diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 91677d071db..b182b1df071 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -355,6 +355,12 @@ class MrpWorkorder(models.Model): }) else: production_move.quantity_done += self.qty_producing + + if not self.next_work_order_id: + for by_product_move in self.production_id.move_finished_ids.filtered(lambda x: (x.product_id.id != self.production_id.product_id.id) and (x.state not in ('done', 'cancel'))): + if by_product_move.has_tracking == 'none': + by_product_move.quantity_done += self.qty_producing * by_product_move.unit_factor + # Update workorder quantity produced self.qty_produced += self.qty_producing