[FIX] mrp: prevent suppression of bom if used in mo
authorMartin Trigaux <mat@odoo.com>
Mon, 10 Nov 2014 14:36:40 +0000 (15:36 +0100)
committerMartin Trigaux <mat@odoo.com>
Mon, 10 Nov 2014 14:37:53 +0000 (15:37 +0100)
The field bom_id is required on a manufacturing order and deleting a mrp.bom would block the current mo.
Restrict the suppression for manufacturing order in progress.
Fixes #3417

addons/mrp/mrp.py

index 72226e9..45b2bcb 100644 (file)
@@ -379,6 +379,13 @@ class mrp_bom(osv.osv):
         default.update(name=_("%s (copy)") % (bom_data['name']), bom_id=False)
         return super(mrp_bom, self).copy_data(cr, uid, id, default, context=context)
 
+    def unlink(self, cr, uid, ids, context=None):
+        if self.pool['mrp.production'].search(cr, uid, [
+                ('bom_id', 'in', ids), ('state', 'not in', ['done', 'cancel'])
+            ], context=context):
+            raise osv.except_osv(_('Warning!'), _('You can not delete a Bill of Material with running manufacturing orders.\nPlease close or cancel it first.'))
+        return super(mrp_bom, self).unlink(cr, uid, ids, context=context)
+
 
 def rounding(f, r):
     # TODO for trunk: log deprecation warning