[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#70975

X-original-commit: e8c1f6b1a3f58b68181bf4d2599bd37efb83b5c7
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
William Henrotin
2021-05-18 11:58:11 +00:00
committed by Andrea Grazioso (agr-odoo)
parent 7923ec5898
commit e43c424fd9
3 changed files with 37 additions and 1 deletions
+8
View File
@@ -194,6 +194,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 _action_assign(self):
res = super(StockMove, self)._action_assign()
for move in self.filtered(lambda x: x.production_id or x.raw_material_production_id):
+28
View File
@@ -377,6 +377,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)
+1 -1
View File
@@ -215,7 +215,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'), '&amp;', ('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'), '&amp;', ('state', '!=', 'draft'), ('additional', '=', False) ]}"/>