Fix #21761 Correct numbering by adding/updating the BomLine and clean code.
This commit is contained in:
Laurent Destailleur 2022-08-22 13:10:19 +02:00 committed by GitHub
commit 3bcd143d5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 43 deletions

View File

@ -181,24 +181,10 @@ if (empty($reshook)) {
}
if (!$error) {
$bomline = new BOMLine($db);
$bomline->fk_bom = $id;
$bomline->fk_product = $idprod;
$bomline->fk_bom_child = $bom_child_id;
$bomline->qty = $qty;
$bomline->qty_frozen = (int) $qty_frozen;
$bomline->disable_stock_change = (int) $disable_stock_change;
$bomline->efficiency = $efficiency;
$result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null);
// Rang to use
$rangmax = $object->line_max(0);
$ranktouse = $rangmax + 1;
$bomline->position = ($ranktouse + 1);
$result = $bomline->create($user);
if ($result <= 0) {
setEventMessages($bomline->error, $bomline->errors, 'errors');
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
} else {
unset($_POST['idprod']);
@ -207,13 +193,11 @@ if (empty($reshook)) {
unset($_POST['disable_stock_change']);
$object->fetchLines();
$object->calculateCosts();
}
}
}
// Add line
// Update line
if ($action == 'updateline' && $user->rights->bom->write) {
$langs->load('errors');
$error = 0;
@ -229,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;