diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index a763380185a4d0700139f078b9be658a58f67877..76909687285d7e2f086e8f2ece34c75e31a1d58d 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -204,6 +204,14 @@ class StockMove(models.Model): defaults['additional'] = True return defaults + def write(self, vals): + if 'product_uom_qty' in vals and 'move_line_ids' in vals: + # first update lines then product_uom_qty as the later will unreserve + # so possibly unlink lines + move_line_vals = vals.pop('move_line_ids') + super().write({'move_line_ids': move_line_vals}) + return super().write(vals) + def unlink(self): # Avoid deleting move related to active MO for move in self: diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 3f20e9e41b80477344bcfa9af72e23b5e47b4be4..798ffe25dc1b4409f86d0599f3aeacc33a9f6e02 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -345,6 +345,34 @@ class TestMrpOrder(TestMrpCommon): production.workorder_ids[0].button_start() self.assertEqual(production.workorder_ids.qty_producing, 5, "Wrong quantity is suggested to produce.") + def test_update_quantity_5(self): + bom = self.env['mrp.bom'].create({ + 'product_id': self.product_6.id, + 'product_tmpl_id': self.product_6.product_tmpl_id.id, + 'product_qty': 1, + 'product_uom_id': self.product_6.uom_id.id, + 'type': 'normal', + 'bom_line_ids': [ + (0, 0, {'product_id': self.product_2.id, 'product_qty': 3}), + ], + }) + production_form = Form(self.env['mrp.production']) + production_form.product_id = self.product_6 + production_form.bom_id = bom + production_form.product_qty = 1 + production_form.product_uom_id = self.product_6.uom_id + production = production_form.save() + production.action_confirm() + production.action_assign() + production_form = Form(production) + # change the quantity producing and the initial demand + # in the same transaction + production_form.qty_producing = 10 + with production_form.move_raw_ids.edit(0) as move: + move.product_uom_qty = 2 + production = production_form.save() + production.button_mark_done() + def test_update_plan_date(self): """Editing the scheduled date after planning the MO should unplan the MO, and adjust the date on the stock moves""" planned_date = datetime(2023, 5, 15, 9, 0) diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index 3102fbfca167b1cffa1b4d47c07d576046861e62..583a458dee7b29968c01f980cdd1baf4f25a4e66 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -212,7 +212,7 @@ <notebook> <page string="Components" name="components"> <field name="move_raw_ids" - context="{'default_product_uom_qty': 1.0, 'default_date': date_planned_start, 'default_date_deadline': date_deadline, 'default_location_id': location_src_id, 'default_location_dest_id': production_location_id, 'default_state': 'draft', 'default_raw_material_production_id': id, 'default_picking_type_id': picking_type_id, 'default_company_id': company_id}" + context="{'default_date': date_planned_start, 'default_date_deadline': date_deadline, 'default_location_id': location_src_id, 'default_location_dest_id': production_location_id, 'default_state': 'draft', 'default_raw_material_production_id': id, 'default_picking_type_id': picking_type_id, 'default_company_id': company_id}" attrs="{'readonly': ['|', ('state', '=', 'cancel'), '&', ('state', '=', 'done'), ('is_locked', '=', True)]}" options="{'delete': [('state', '=', 'draft')]}"> <tree default_order="is_done,sequence" editable="bottom"> <field name="product_id" force_save="1" required="1" context="{'default_type': 'product'}" attrs="{'readonly': ['|', '|', ('has_move_lines', '=', True), ('state', '=', 'cancel'), '&', ('state', '!=', 'draft'), ('additional', '=', False) ]}"/>