[FIX] mrp: when changing bom, update MO as in form
Steps to reproduce (Manufacturing app): - Configuration -> Settings -> Activate `Work Orders` and `By-products`. - Products -> Bill of Materials - Create 2 BoM for a single product (e.g. Product A), both with operations and a byproduct each (e.g. BP A & BP B). - Operations -> Manufacturing Orders. - Create a MO for Product A and save it. - Mo was created using the first BoM and has its operations & byproducts set in their respective tabs. - Update the MO from first to second BoM. Adding another byproduct, deleting it or updating it before saving won't persist after save (it will revert to what's defined in the BoM) This is due to `move_finished_ids` holding the values defined in the BoM in the call to `write()` while `move_byproduct_ids` holds the correct (current) values. But since `move_byproduct_ids` is only a subset of `move_finished_ids`, it's not used in the write operation. Task-3277166 closes odoo/odoo#127143 X-original-commit: 0fb2cd02622c1670ee91df48ff22a320da1b02a0 Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com> Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>
This commit is contained in:
@@ -801,6 +801,18 @@ class MrpProduction(models.Model):
|
||||
if 'move_byproduct_ids' in vals and 'move_finished_ids' not in vals:
|
||||
vals['move_finished_ids'] = vals.get('move_finished_ids', []) + vals['move_byproduct_ids']
|
||||
del vals['move_byproduct_ids']
|
||||
if 'bom_id' in vals and 'move_byproduct_ids' in vals and 'move_finished_ids' in vals:
|
||||
# If byproducts are given, they take precedence over move_finished for byproduts definition
|
||||
bom = self.env['mrp.bom'].browse(vals.get('bom_id'))
|
||||
bom_product = bom.product_id or bom.product_tmpl_id.product_variant_id
|
||||
joined_move_ids = vals.get('move_byproduct_ids', [])
|
||||
for move_finished in vals.get('move_finished_ids', []):
|
||||
# Remove CREATE lines from finished_ids as they do not reflect the form current state (nor the byproduct vals)
|
||||
if move_finished[0] == Command.CREATE and move_finished[2].get('product_id') != bom_product.id:
|
||||
continue
|
||||
joined_move_ids.append(move_finished)
|
||||
vals['move_finished_ids'] = joined_move_ids
|
||||
del vals['move_byproduct_ids']
|
||||
if 'workorder_ids' in self:
|
||||
production_to_replan = self.filtered(lambda p: p.is_planned)
|
||||
if 'move_raw_ids' in vals and self.state not in ['draft', 'cancel', 'done']:
|
||||
|
||||
Reference in New Issue
Block a user