From 18171b1e5297abe01291d4fc962fa296f9edf8c7 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Wed, 24 Apr 2019 14:03:06 +0000 Subject: [PATCH] [FIX] mrp: wrong use of self The method _workorder_line_ids() is defined on mrp.workorder while `self` is an instance of change_production_qty wizard in this case. Without this commit, changing the quantity to produce of a manufactoring order with workorders already planned raised a traceback. --- addons/mrp/tests/test_workorder_operation.py | 23 ++++++++++++++++++++ addons/mrp/wizard/change_production_qty.py | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addons/mrp/tests/test_workorder_operation.py b/addons/mrp/tests/test_workorder_operation.py index 474aa909168..afcba693390 100644 --- a/addons/mrp/tests/test_workorder_operation.py +++ b/addons/mrp/tests/test_workorder_operation.py @@ -827,3 +827,26 @@ class TestWorkOrderProcess(TestMrpCommon): # Check that the workorder is planned now and that it lasts one hour self.assertEqual(workorder.date_planned_start, date_start, msg="Workorder should be planned tomorrow.") self.assertEqual(workorder.date_planned_finished, date_start + timedelta(hours=1), msg="Workorder should be done one hour later.") + + def test_change_production_1(self): + """Change the quantity to produce on the MO while workorders are already planned.""" + dining_table = self.env.ref("mrp.product_product_computer_desk") + dining_table.tracking = 'lot' + production_table_form = Form(self.env['mrp.production']) + production_table_form.product_id = dining_table + production_table_form.bom_id = self.env.ref("mrp.mrp_bom_desk") + production_table_form.product_qty = 1.0 + production_table_form.product_uom_id = dining_table.uom_id + production_table = production_table_form.save() + production_table.action_confirm() + + # Create work order + production_table.button_plan() + + context = {'active_id': production_table.id, 'active_model': 'mrp.production'} + change_qty_form = Form(self.env['change.production.qty'].with_context(context)) + change_qty_form.product_qty = 2.00 + change_qty = change_qty_form.save() + change_qty.change_prod_qty() + + self.assertEqual(production_table.workorder_ids[0].qty_producing, 2, "Quantity to produce not updated") diff --git a/addons/mrp/wizard/change_production_qty.py b/addons/mrp/wizard/change_production_qty.py index 01a3807a70d..d6ac8296356 100644 --- a/addons/mrp/wizard/change_production_qty.py +++ b/addons/mrp/wizard/change_production_qty.py @@ -106,7 +106,7 @@ class ChangeProductionQty(models.TransientModel): (moves_finished + moves_raw).write({'workorder_id': wo.id}) if wo.state not in ('done', 'cancel'): line_values = wo._update_workorder_lines() - self._workorder_line_ids().create(line_values['to_create']) + wo._workorder_line_ids().create(line_values['to_create']) if line_values['to_delete']: line_values['to_delete'].unlink() for line, vals in line_values['to_update'].items():