From d5c31e231aecc130b695f914441a6c6d29b02f0a Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Thu, 25 Oct 2018 12:25:50 +0000 Subject: [PATCH] [REV] mrp: block updating live BoM This reverts commit d78b6f5e25eb7bf36aef57d1ae1c5c6e51d1ec7b. 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 --- addons/mrp/models/mrp_bom.py | 11 ----------- addons/mrp/tests/test_bom.py | 16 ---------------- addons/mrp/tests/test_workorder_operation.py | 2 +- 3 files changed, 1 insertion(+), 28 deletions(-) diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py index fcab8f82015..8032cad2b60 100644 --- a/addons/mrp/models/mrp_bom.py +++ b/addons/mrp/models/mrp_bom.py @@ -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: diff --git a/addons/mrp/tests/test_bom.py b/addons/mrp/tests/test_bom.py index 354babff84a..44fd56b6431 100644 --- a/addons/mrp/tests/test_bom.py +++ b/addons/mrp/tests/test_bom.py @@ -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}) diff --git a/addons/mrp/tests/test_workorder_operation.py b/addons/mrp/tests/test_workorder_operation.py index 4066a8d33ab..49df9007835 100644 --- a/addons/mrp/tests/test_workorder_operation.py +++ b/addons/mrp/tests/test_workorder_operation.py @@ -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]