diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 383fd45c095..5fa2ee90a9f 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -655,6 +655,8 @@ class Mo extends CommonObject $moline = new MoLine($this->db); $moline->fk_mo = $this->id; + $moline->origin_id = $line->id; + $moline->origin_type = 'bom'; if ($line->qty_frozen) { $moline->qty = $line->qty; // Qty to consume does not depends on quantity to produce } else { @@ -1386,6 +1388,8 @@ class MoLine extends CommonObjectLine public $fields = array( 'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10), 'fk_mo' =>array('type'=>'integer', 'label'=>'Mo', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>15), + 'origin_id' =>array('type'=>'integer', 'label'=>'Origin', 'enabled'=>1, 'visible'=>-1, 'notnull'=>0, 'position'=>17), + 'origin_type' =>array('type'=>'varchar(10)', 'label'=>'Origin type', 'enabled'=>1, 'visible'=>-1, 'notnull'=>0, 'position'=>18), 'position' =>array('type'=>'integer', 'label'=>'Position', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20), 'fk_product' =>array('type'=>'integer', 'label'=>'Product', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25), 'fk_warehouse' =>array('type'=>'integer', 'label'=>'Warehouse', 'enabled'=>1, 'visible'=>-1, 'position'=>30), @@ -1405,6 +1409,8 @@ class MoLine extends CommonObjectLine public $rowid; public $fk_mo; + public $origin_id; + public $origin_type; public $position; public $fk_product; public $fk_warehouse; diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index eb40b1d6f8b..bd254c404d4 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -151,7 +151,8 @@ if (empty($reshook)) $moline->fk_mo = $object->id; $moline->qty = GETPOST('qtytoadd', 'int'); ; $moline->fk_product = GETPOST('productidtoadd', 'int'); - $moline->role = 'toconsumef'; // free consume line + $moline->role = 'toconsume'; + $moline->origin_type = 'free'; // free consume line $moline->position = 0; $resultline = $moline->create($user, false); // Never use triggers here @@ -173,7 +174,7 @@ if (empty($reshook)) $pos = 0; // Process line to consume foreach ($object->lines as $line) { - if (preg_match('/toconsume/', $line->role)) { + if ($line->role == 'toconsume') { $tmpproduct = new Product($db); $tmpproduct->fetch($line->fk_product); @@ -311,7 +312,7 @@ if (empty($reshook)) if (GETPOST('autoclose', 'int')) { foreach ($object->lines as $line) { - if (preg_match('/toconsume/', $line->role)) { + if ($line->role == 'toconsume') { $arrayoflines = $object->fetchLinesLinked('consumed', $line->id); $alreadyconsumed = 0; foreach ($arrayoflines as $line2) { @@ -695,7 +696,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'; $newlinetext = ''; - if (($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) && $action != 'consumeorproduce' && $action != 'consumeandproduceall') { + if ($object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED && $action != 'consumeorproduce' && $action != 'consumeandproduceall') { $newlinetext = 'id.'&action=addconsumeline">'.$langs->trans("AddNewConsumeLines").''; } print load_fiche_titre($langs->trans('Consumption'), '', '', 0, '', '', $newlinetext); @@ -749,13 +750,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $nblinetoconsumecursor = 0; foreach ($object->lines as $line) { - if (preg_match('/toconsume/', $line->role)) { + if ($line->role == 'toconsume') { $nblinetoconsumecursor++; $tmpproduct = new Product($db); $tmpproduct->fetch($line->fk_product); - if (!empty($bomcost) && $line->role == 'toconsumef' && $object->qty > 0) { + if ($line->origin_type == 'free' && $object->qty > 0) { // add free consume line cost to bomcost require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; $productFournisseur = new ProductFournisseur($db);