diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index b04f5430adc75..5c8fb1cfebf2d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4847,6 +4847,15 @@ public function isObjectUsed($id = 0, $entity = 0) $haschild = 0; foreach ($arraytoscan as $table => $element) { //print $id.'-'.$table.'-'.$elementname.'
'; + + // Check if module is enabled (to avoid error if tables of module not created) + if (isset($element['enabled']) && !empty($element['enabled'])) { + $enabled = (int) dol_eval($element['enabled'], 1); + if (empty($enabled)) { + continue; + } + } + // Check if element can be deleted $sql = "SELECT COUNT(*) as nb"; $sql .= " FROM ".$this->db->prefix().$table." as c"; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 44ea25236e627..f14814bc21086 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -87,9 +87,9 @@ class Product extends CommonObject 'contratdet' => array('name' => 'Contract', 'parent' => 'contrat', 'parentkey' => 'fk_contrat'), 'facture_fourn_det' => array('name' => 'SupplierInvoice', 'parent' => 'facture_fourn', 'parentkey' => 'fk_facture_fourn'), 'commande_fournisseurdet' => array('name' => 'SupplierOrder', 'parent' => 'commande_fournisseur', 'parentkey' => 'fk_commande'), - 'mrp_production' => array('name' => 'Mo', 'parent' => 'mrp_mo', 'parentkey' => 'fk_mo' ), - 'bom_bom' => array('name' => 'BOM'), - 'bom_bomline' => array('name' => 'BOMLine', 'parent' => 'bom_bom', 'parentkey' => 'fk_bom'), + 'mrp_production' => array('name' => 'Mo', 'parent' => 'mrp_mo', 'parentkey' => 'fk_mo', 'enabled' => 'isModEnabled("mrp")'), + 'bom_bom' => array('name' => 'BOM', 'enabled' => 'isModEnabled("bom")'), + 'bom_bomline' => array('name' => 'BOMLine', 'parent' => 'bom_bom', 'parentkey' => 'fk_bom', 'enabled' => 'isModEnabled("bom")'), ); /**