Merge pull request #24553 from atm-lena/NEW_MoBom_AddLine_DefaultWorkstation

New mo bom add line default workstation
This commit is contained in:
Laurent Destailleur 2023-04-26 22:11:27 +02:00 committed by GitHub
commit 9a041774f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 4 deletions

View File

@ -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');

View File

@ -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)
);
/**

View File

@ -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 '<td class="linecolunit nowrap right">';
print '<td class="linecolworkstation nowrap right">';
$coldisplay++;
if ($res > 0) echo $workstation->getNomUrl();
print '</td>';

View File

@ -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;

View File

@ -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++;