From d7fdb636b81a99519d1e186edaf42d36ecee3b5f Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 13 Feb 2018 10:41:03 +0100 Subject: [PATCH] [FIX]mrp, mrp_byproduct: Qty is not "produced" for Byproducts When producing a product as a BoM, the quantity for the byproduct was not increased in "produced". opw:814768 --- addons/mrp/models/mrp_workorder.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 69b095cd0f7..6f640d6c695 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -312,20 +312,24 @@ class MrpWorkorder(models.Model): # If last work order, then post lots used # TODO: should be same as checking if for every workorder something has been done? if not self.next_work_order_id: - production_move = 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 production_move.product_id.tracking != 'none': - move_lot = production_move.move_lot_ids.filtered(lambda x: x.lot_id.id == self.final_lot_id.id) - if move_lot: - move_lot.quantity += self.qty_producing + production_moves = self.production_id.move_finished_ids.filtered(lambda x: (x.state not in ('done', 'cancel'))) + for production_move in production_moves: + if production_move.product_id.id == self.production_id.product_id.id and production_move.product_id.tracking != 'none': + move_lot = production_move.move_lot_ids.filtered(lambda x: x.lot_id.id == self.final_lot_id.id) + if move_lot: + move_lot.quantity += self.qty_producing + else: + move_lot.create({'move_id': production_move.id, + 'lot_id': self.final_lot_id.id, + 'quantity': self.qty_producing, + 'quantity_done': self.qty_producing, + 'workorder_id': self.id, + }) + elif production_move.unit_factor: + rounding = production_move.product_uom.rounding + production_move.quantity_done += float_round(self.qty_producing * production_move.unit_factor, precision_rounding=rounding) else: - move_lot.create({'move_id': production_move.id, - 'lot_id': self.final_lot_id.id, - 'quantity': self.qty_producing, - 'quantity_done': self.qty_producing, - 'workorder_id': self.id, - }) - else: - production_move.quantity_done += self.qty_producing # TODO: UoM conversion? + production_move.quantity_done += self.qty_producing # TODO: UoM conversion? # Update workorder quantity produced self.qty_produced += self.qty_producing