[REV] mrp: block updating live BoM

This reverts commit d78b6f5e25.

This constraint is considered too harsh. It was applied to circumvent
inconsistencies when a bom is modified while being used in a
manufacturing order and the user chose to update the quantity to
produce. The current code will look at the existing move if no
intermaddite post of inventory was done else look at the new bom.

A code to re-construct the original BoM from the stock moves isn't easy
to write to handle all cases, one particularly complicated is the
deletion of bom lines of the same product.

We also considered to block the update qty button if the bom is modified
after the create date of the MO, but if we have to read all the bom
lines of all the sub bom in a computed field it may be slow on large
databases.

We thus chose to remove the constraint and think of a better approach in
a future version.

task 1891407

closes odoo/odoo#28155
This commit is contained in:
Simon Lejeune
2018-10-25 12:25:50 +00:00
parent 5494b0bc3e
commit d5c31e231a
3 changed files with 1 additions and 28 deletions
-11
View File
@@ -68,17 +68,6 @@ class MrpBom(models.Model):
for line in self.bom_line_ids:
line.attribute_value_ids = False
@api.multi
def write(self, values):
mos = self.env['mrp.production'].search_count([
('bom_id', 'in', self.ids),
('state', 'not in', ['done', 'cancel'])
])
if mos and any(k not in ['code', 'sequence', 'pick_type_id', 'ready_to_produce'] for k in values.keys()):
raise ValidationError(_('This BoM is used in some Manufacturing Orders that are still open. You should rather archive this BoM and create a new one.'))
return super(MrpBom, self).write(values)
@api.constrains('product_id', 'product_tmpl_id', 'bom_line_ids')
def _check_product_recursion(self):
for bom in self:
-16
View File
@@ -228,19 +228,3 @@ class TestBoM(TestMrpCommon):
})
# Check consumed materials in production order.
self.assertEqual(mrp_order.move_raw_ids.mapped('product_id').ids, consu_product_ids)
def test_update_bom(self):
"""Update a BoM used in open production should raise an error"""
mo = self.env['mrp.production'].create({
'name': 'MO 1',
'product_id': self.product_1.id,
'product_uom_id': self.product_1.uom_id.id,
'product_qty': 2,
'bom_id': self.bom_1.id,
})
mo.button_plan()
# update an authorized field
self.bom_1.write({'code': 'Hello'})
# update a not authorized field
with self.assertRaises(exceptions.ValidationError):
self.bom_1.write({'product_id': self.product_2.id})
+1 -1
View File
@@ -124,7 +124,7 @@ class TestWorkOrderProcess(common.TransactionCase):
self.env['stock.move'].search([('product_id', '=', product_bolt.id)])._do_unreserve()
product_bolt.type = 'product'
bom = self.env['mrp.bom'].browse(self.ref("mrp.mrp_bom_desk")).copy()
bom = self.env['mrp.bom'].browse(self.ref("mrp.mrp_bom_desk"))
bom.routing_id = self.ref('mrp.mrp_routing_1')
bom.bom_line_ids.filtered(lambda p: p.product_id == product_table_sheet).operation_id = bom.routing_id.operation_ids[0]