diff options
| author | William Henrotin <whe@odoo.com> | 2021-04-16 09:30:23 +0000 |
|---|---|---|
| committer | Andrea Grazioso (agr-odoo) <agr@odoo.com> | 2021-05-10 14:39:39 +0000 |
| commit | d1e49723349cb5a44cf353f4dd12a1d55e076155 (patch) | |
| tree | afc21cbb952621d2af5ec4297bee6c70216f3e46 | |
| parent | 9b3506523659b06440b46664eeb83952cc30694e (diff) | |
[FIX] mrp: split call to write on stock move
You can, in a production order, change the quantity done of a stock move
raw and change its initial demand ('To Consume' field) in the same
transaction. This can lead to some issue as changing the quantity done
will update the stock move line and changing the initial demand will
unreserve the stock move thus impacting the stock move lines too.
This commit will split the values to update of a stock in move in case
the two fields have to be updated. First the stock move lines, then the
initial demand.
This commit also remove the default_product_uom_qty in the move_raw_ids
fields. This ensure the onchanges do not create/edit any stock move lines
with some reserved quantity.
opw : 2451298
closes odoo/odoo#69377
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
| -rw-r--r-- | addons/mrp/models/stock_move.py | 8 | ||||
| -rw-r--r-- | addons/mrp/tests/test_order.py | 28 | ||||
| -rw-r--r-- | addons/mrp/views/mrp_production_views.xml | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index a763380185a..76909687285 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 3f20e9e41b8..798ffe25dc1 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 3102fbfca16..583a458dee7 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) ]}"/> |
