From 29df21d768d4398edddcf1949cfbf79017724d18 Mon Sep 17 00:00:00 2001 From: Christian Humpel Date: Tue, 16 Aug 2022 22:25:52 +0200 Subject: [PATCH 1/5] Fix #21761 Remove dopple +1 on $ranktouse. --- htdocs/bom/bom_card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index ee619a589e3..f67c4819efc 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -194,7 +194,7 @@ if (empty($reshook)) { $rangmax = $object->line_max(0); $ranktouse = $rangmax + 1; - $bomline->position = ($ranktouse + 1); + $bomline->position = $ranktouse; $result = $bomline->create($user); if ($result <= 0) { From 474d82b19c957fa42b0bf929b46061b31cd982db Mon Sep 17 00:00:00 2001 From: Christian Humpel Date: Wed, 17 Aug 2022 11:02:26 +0200 Subject: [PATCH 2/5] Clean Code: Remove duplicate code form bom_card.php --- htdocs/bom/bom_card.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index ee619a589e3..6743ec3c761 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -181,24 +181,11 @@ 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; - // Rang to use - $rangmax = $object->line_max(0); - $ranktouse = $rangmax + 1; + $result = $object->addLine($idprod,$qty,$qty_frozen,$disable_stock_change,$efficiency,-1,$bom_child_id,null); - $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,8 +194,6 @@ if (empty($reshook)) { unset($_POST['disable_stock_change']); $object->fetchLines(); - - $object->calculateCosts(); } } } From 01d7f558ba56cf3085327eeea9dd3317f6dfdfee Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 17 Aug 2022 09:11:09 +0000 Subject: [PATCH 3/5] Fixing style errors. --- htdocs/bom/bom_card.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 6743ec3c761..2eff03dce82 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -181,8 +181,7 @@ if (empty($reshook)) { } if (!$error) { - - $result = $object->addLine($idprod,$qty,$qty_frozen,$disable_stock_change,$efficiency,-1,$bom_child_id,null); + $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null); if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); From 115a2cdc9e41d4748be79155d7858285e316a988 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 17 Aug 2022 22:02:20 +0000 Subject: [PATCH 4/5] Fixing style errors. --- htdocs/bom/bom_card.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index d31087d4e8a..2eff03dce82 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -181,7 +181,6 @@ if (empty($reshook)) { } if (!$error) { - $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null); if ($result <= 0) { From 326c8762bb80b309e1d8f1f58684aed14af9eff1 Mon Sep 17 00:00:00 2001 From: Christian Humpel Date: Fri, 19 Aug 2022 17:29:05 +0200 Subject: [PATCH 5/5] Fix #21761 Correct numbering by adding/updating the BomLine and clean code. --- htdocs/bom/bom_card.php | 34 ++++++++++++++--------------- htdocs/bom/class/api_boms.class.php | 1 - htdocs/bom/class/bom.class.php | 8 ++----- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 2eff03dce82..5466fb54f8f 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -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(); + } } } } diff --git a/htdocs/bom/class/api_boms.class.php b/htdocs/bom/class/api_boms.class.php index 3c06a658b96..fb7d175a229 100644 --- a/htdocs/bom/class/api_boms.class.php +++ b/htdocs/bom/class/api_boms.class.php @@ -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 ); diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index e774e4ddacf..ec659502e60 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -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;