diff --git a/addons/mrp/models/mrp_abstract_workorder.py b/addons/mrp/models/mrp_abstract_workorder.py index fcd4256fb6dbf..54b31101140bb 100644 --- a/addons/mrp/models/mrp_abstract_workorder.py +++ b/addons/mrp/models/mrp_abstract_workorder.py @@ -58,7 +58,7 @@ def _update_workorder_lines(self): self.production_id.product_uom_id, round=False ) - qty_todo = float_round(new_qty - sum(move_workorder_lines.mapped('qty_done')), precision_rounding=rounding) + qty_todo = float_round(new_qty - sum(move_workorder_lines.mapped('qty_to_consume')), precision_rounding=rounding) # Remove or lower quantity on exisiting workorder lines if float_compare(qty_todo, 0.0, precision_rounding=rounding) < 0: @@ -95,7 +95,7 @@ def _update_workorder_lines(self): if float_compare(qty_reserved_remaining, 0, precision_rounding=rounding) > 0: qty_to_add = min(qty_reserved_remaining, qty_todo) line_values['to_update'][workorder_line] = { - 'qty_done': workorder_line.qty_done + qty_to_add, + 'qty_done': workorder_line.qty_to_consume + qty_to_add, 'qty_to_consume': workorder_line.qty_to_consume + qty_to_add, 'qty_reserved': workorder_line.qty_reserved + qty_to_add, } @@ -104,7 +104,7 @@ def _update_workorder_lines(self): if not workorder_line.qty_reserved and not workorder_line.lot_id and workorder_line.product_tracking != 'serial': line_values['to_update'][workorder_line] = { - 'qty_done': workorder_line.qty_done + qty_todo, + 'qty_done': workorder_line.qty_to_consume + qty_todo, 'qty_to_consume': workorder_line.qty_to_consume + qty_todo, } qty_todo = 0 diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index e96527e15541f..136537c13f713 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -108,15 +108,16 @@ class MrpWorkorder(models.Model): @api.depends('production_id') def _compute_final_lot_domain(self): - # check if self is not the first workorder in the list - if self.env['mrp.workorder'].search([('next_work_order_id', '=', self.id)]): - self.final_lot_domain = self.env['stock.production.lot'].search([ - ('use_next_on_work_order_id', '=', self.id), - ]).ids - else: - self.final_lot_domain = self.env['stock.production.lot'].search([ - ('product_id', '=', self.product_id.id), - ]).ids + for wo in self: + # check if self is not the first workorder in the list + if self.env['mrp.workorder'].search([('next_work_order_id', '=', wo.id)]): + wo.final_lot_domain = self.env['stock.production.lot'].search([ + ('use_next_on_work_order_id', '=', wo.id), + ]).ids + else: + wo.final_lot_domain = self.env['stock.production.lot'].search([ + ('product_id', '=', wo.product_id.id), + ]).ids @api.multi def name_get(self): diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 438bff2a52eaf..99827f021fea8 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -479,6 +479,20 @@ def test_product_produce_1(self): 'active_id': mo.id, 'active_ids': [mo.id], })) + # change the quantity done in one line + produce_form.workorder_line_ids._records[0]['qty_done'] = 1 + + # change the quantity producing + produce_form.qty_producing = 3 + + # check than all quantities are update correctly + line1 = produce_form.workorder_line_ids._records[0] + line2 = produce_form.workorder_line_ids._records[1] + self.assertEqual(line1['qty_to_consume'], 3, "Wrong quantity to consume") + self.assertEqual(line1['qty_done'], 3, "Wrong quantity done") + self.assertEqual(line2['qty_to_consume'], 12, "Wrong quantity to consume") + self.assertEqual(line2['qty_done'], 12, "Wrong quantity done") + product_produce = produce_form.save() self.assertEqual(len(product_produce.workorder_line_ids), 2, 'You should have produce lines even the consumed products are not tracked.') product_produce.do_produce() diff --git a/addons/mrp/views/stock_move_views.xml b/addons/mrp/views/stock_move_views.xml index 46b52a10513a8..0fa775ad12f55 100644 --- a/addons/mrp/views/stock_move_views.xml +++ b/addons/mrp/views/stock_move_views.xml @@ -26,7 +26,7 @@