Fix #21761 Correct numbering by adding/updating the BomLine and clean code.

This commit is contained in:
Christian Humpel 2022-08-19 17:29:05 +02:00
parent e1de08467b
commit 326c8762bb
3 changed files with 18 additions and 25 deletions

View File

@ -197,7 +197,7 @@ if (empty($reshook)) {
}
}
// Add line
// Update line
if ($action == 'updateline' && $user->rights->bom->write) {
$langs->load('errors');
$error = 0;
@ -213,26 +213,24 @@ if (empty($reshook)) {
$error++;
}
$bomline = new BOMLine($db);
$bomline->fetch($lineid);
$bomline->qty = $qty;
$bomline->qty_frozen = (int) $qty_frozen;
$bomline->disable_stock_change = (int) $disable_stock_change;
$bomline->efficiency = $efficiency;
if (!$error) {
$result = $bomline->update($user);
if ($result <= 0) {
setEventMessages($bomline->error, $bomline->errors, 'errors');
$action = '';
} else {
unset($_POST['idprod']);
unset($_POST['qty']);
unset($_POST['qty_frozen']);
unset($_POST['disable_stock_change']);
$bomline = new BOMLine($db);
$bomline->fetch($lineid);
$object->fetchLines();
$result = $object->updateLine($lineid, $qty, (int)$qty_frozen, (int)$disable_stock_change, $efficiency, $bomline->position, $bomline->import_key);
$object->calculateCosts();
if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
} else {
unset($_POST['idprod']);
unset($_POST['qty']);
unset($_POST['qty_frozen']);
unset($_POST['disable_stock_change']);
$object->fetchLines();
}
}
}
}

View File

@ -391,7 +391,6 @@ class Boms extends DolibarrApi
$request_data->disable_stock_change,
$request_data->efficiency,
$request_data->position,
$request_data->fk_bom_child,
$request_data->import_key
);

View File

@ -616,13 +616,13 @@ class BOM extends CommonObject
* @param string $import_key Import Key
* @return int <0 if KO, Id of updated BOM-Line if OK
*/
public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null)
public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $import_key = null)
{
global $mysoc, $conf, $langs, $user;
$logtext = "::updateLine bomid=$this->id, qty=$qty, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency";
$logtext .= ", fk_bom_child=$fk_bom_child, import_key=$import_key";
$logtext .= ", import_key=$import_key";
dol_syslog(get_class($this).$logtext, LOG_DEBUG);
if ($this->statut == self::STATUS_DRAFT) {
@ -641,9 +641,6 @@ class BOM extends CommonObject
if (empty($efficiency)) {
$efficiency = 1.0;
}
if (empty($fk_bom_child)) {
$fk_bom_child = null;
}
if (empty($import_key)) {
$import_key = null;
}
@ -688,7 +685,6 @@ class BOM extends CommonObject
$this->line->qty_frozen = $qty_frozen;
$this->line->disable_stock_change = $disable_stock_change;
$this->line->efficiency = $efficiency;
$this->line->fk_bom_child = $fk_bom_child;
$this->line->import_key = $import_key;
$this->line->position = $rankToUse;