summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2018-08-23 15:19:27 +0200
committerWilliam Henrotin <whe@odoo.com>2018-08-23 20:32:27 +0200
commitd78b6f5e25eb7bf36aef57d1ae1c5c6e51d1ec7b (patch)
treea637dedd9838926e316258914acf43812d81e390 /addons
parentdc91e3cb0e92a194fc9326f2fe254b7294848d2e (diff)
[IMP] mrp: block updating live BoM
When modifying a BoM that is used in a MO not done, raise a blocking warning to avoid inconsistenties at production. Proudly pair programmed with pim <pim@odoo.com>. Some mrp tests has been adapted to not raise the new error. They used demo data while they should created inside the test. This commit is related to task id : 1855566
Diffstat (limited to 'addons')
-rw-r--r--addons/mrp/models/mrp_bom.py11
-rw-r--r--addons/mrp/tests/test_bom.py16
-rw-r--r--addons/mrp/tests/test_workorder_operation.py2
3 files changed, 28 insertions, 1 deletions
diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py
index 58df0ad6d14..80799006a03 100644
--- a/addons/mrp/models/mrp_bom.py
+++ b/addons/mrp/models/mrp_bom.py
@@ -68,6 +68,17 @@ 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 44fd56b6431..354babff84a 100644
--- a/addons/mrp/tests/test_bom.py
+++ b/addons/mrp/tests/test_bom.py
@@ -228,3 +228,19 @@ 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 49df9007835..4066a8d33ab 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"))
+ bom = self.env['mrp.bom'].browse(self.ref("mrp.mrp_bom_desk")).copy()
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]