From 419d32207ab85c57f082167439b79d11d9c8cafc Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Thu, 21 Mar 2019 13:43:00 +0000 Subject: [PATCH 1/3] [FIX] mrp: qty_done and qty_to_consume concistency This commit ensures the qty_to_consume is always adapted to be the same as qty_done in the onchange on qty_processing. This patch is needed to keep the same behaviour before and after the workorder line refactoring 5ef46664a25923e6f9e632fd10e031d4a2e81c26 --- addons/mrp/models/mrp_abstract_workorder.py | 6 +++--- addons/mrp/tests/test_order.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/mrp_abstract_workorder.py b/addons/mrp/models/mrp_abstract_workorder.py index 50f4935375c02..28d81ce1ce79b 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/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() From 799ab731899d510aae4858762e07e01d730c0a9c Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Thu, 21 Mar 2019 15:42:45 +0000 Subject: [PATCH 2/3] [FIX] mrp: handle multi The _compute_final_lot_domain method is implicitely multi but doens't manage the loop over 'self' --- addons/mrp/models/mrp_workorder.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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): From 27e9c9e01179bfe3a53460ec6a6f88b6b7b38215 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 21 Mar 2019 14:33:21 +0000 Subject: [PATCH 3/3] [FIX] mrp: unlock a raw move line Usecase to reproduce: - Go on a Mo - Edit and Unlock - Produce the MO - Update a raw move and add a move line User error you quant write on product_qty fields. product_qty represent the reserved quantity on move line as quant's UoM. The system requires to write a product_uom_qty that represent the same quantity but in the move line UoM. Fix it by removing the fields from the view, so it's no more save. Also set the quantity done as readonly if the lines are present in the view. closes odoo/odoo#32135 Signed-off-by: Arnold Moyaux --- addons/mrp/views/stock_move_views.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 @@