diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index e27cd0a2e1c..b1db4a5c824 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -170,6 +170,13 @@ if (empty($reshook)) { $disable_stock_change = GETPOST('disable_stock_change', 'int'); $efficiency = price2num(GETPOST('efficiency', 'alpha')); $fk_unit = GETPOST('fk_unit', 'alphanohtml'); + + if (!empty($idprod) && $conf->workstation->enabled) { + $product = new Product($db); + $res = $product->fetch($idprod); + if ($res > 0 && $product->type == Product::TYPE_SERVICE) $fk_default_workstation = $product->fk_default_workstation; + } + if ($qty == '') { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); $error++; @@ -206,7 +213,7 @@ if (empty($reshook)) { } } - $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit, $array_options); + $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit, $array_options, $fk_default_workstation); if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index f3975e58125..53081b22fbd 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -572,7 +572,7 @@ class BOM extends CommonObject * @param array $array_options extrafields array * @return int <0 if KO, Id of created object if OK */ - public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null, $fk_unit = '', $array_options = 0) + public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null, $fk_unit = '', $array_options = 0, $fk_default_workstation = null) { global $mysoc, $conf, $langs, $user; @@ -641,6 +641,7 @@ class BOM extends CommonObject $this->line->import_key = $import_key; $this->line->position = $rankToUse; $this->line->fk_unit = $fk_unit; + $this->line->fk_default_workstation = $fk_default_workstation; if (is_array($array_options) && count($array_options) > 0) { $this->line->array_options = $array_options; @@ -1670,6 +1671,7 @@ class BOMLine extends CommonObjectLine 'fk_unit' => array('type'=>'integer', 'label'=>'Unit', 'enabled'=>1, 'visible'=>1, 'position'=>120, 'notnull'=>-1,), 'position' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>1, 'visible'=>0, 'default'=>0, 'position'=>200, 'notnull'=>1,), 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,), + 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>1050) ); /** diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index d000118e1b9..6463f45fbb0 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -158,9 +158,9 @@ if ($filtertype != 1) { // Work station if (isModEnabled('workstation')) { $workstation = new Workstation($object->db); - $res = $workstation->fetch($tmpproduct->fk_default_workstation); + $res = $workstation->fetch($line->fk_default_workstation); - print ''; + print ''; $coldisplay++; if ($res > 0) echo $workstation->getNomUrl(); print ''; diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 46b33051fd9..ad1f1483edd 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -741,6 +741,7 @@ class Mo extends CommonObject $moline->position = $line->position; $moline->qty_frozen = $line->qty_frozen; $moline->disable_stock_change = $line->disable_stock_change; + if (!empty($line->fk_default_workstation)) $moline->fk_default_workstation = $line->fk_default_workstation; $resultline = $moline->create($user, false); // Never use triggers here if ($resultline <= 0) { @@ -1720,6 +1721,7 @@ class MoLine extends CommonObjectLine 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>170), 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModification', 'enabled'=>1, 'visible'=>-1, 'position'=>175), 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>180), + 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>185) ); public $rowid; diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index ac0aa60a647..49a094b89e4 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -169,6 +169,12 @@ if (empty($reshook)) { $moline->origin_type = 'free'; // free consume line $moline->position = 0; + if (!empty($moline->fk_product)) { + $product = new Product($db); + $product->fetch($moline->fk_product); + if ($product->type == Product::TYPE_SERVICE) $moline->fk_default_workstation = $product->fk_default_workstation; + } + $resultline = $moline->create($user, false); // Never use triggers here if ($resultline <= 0) { $error++;