From 3c02819090ea59b10312d528e8b92d4a50cc552a Mon Sep 17 00:00:00 2001 From: Lucky <93642903+LuckyRoussel98@users.noreply.github.com> Date: Thu, 30 Jul 2026 19:24:51 +0300 Subject: [PATCH] Update expedition.class.php (#39314) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update expedition.class.php In Expedition::addline_batch() (expedition.class.php:1284), the creation form submits all batch lines (even those with qty=0), because SHIPMENT_GETS_ALL_ORDER_PRODUCTS=1 forces their inclusion ($value['q'] == 0 && ...SHIPMENT_GETS_ALL_ORDER_PRODUCTS, line 1295). For each line included, the STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT control compared $prod_batch->qty < $linebatch->qty without verifying that $linebatch->qty (the actual quantity requested for this batch) is greater than 0. Result: For the line in batch "azerty" (requested quantity = 0, stock = -10), the -10 < 0 test is true → the entire shipment is rejected with "insufficient stock," even though the batch actually chosen ("azerty123456789", requested quantity = 2, stock = 5) is more than sufficient. * Update expedition.class.php --------- Co-authored-by: Sylvain Legrand Co-authored-by: Laurent Destailleur --- htdocs/expedition/class/expedition.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index ba5efcc76f8..2ed4d1789b3 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1186,13 +1186,13 @@ class Expedition extends CommonObject $product = new Product($this->db); $product->fetch($orderline->fk_product); - if (!($entrepot_id > 0) && !getDolGlobalString('STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS') && !(getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES') && $line->product_type == Product::TYPE_SERVICE) && $product->stockable_product == Product::ENABLED_STOCK) { + if (!($entrepot_id > 0) && !getDolGlobalString('STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS') && !(getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES') && $line->product_type == Product::TYPE_SERVICE) && $product->stockable_product == Product::ENABLED_STOCK && !empty($line->qty)) { $langs->load("errors"); $this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine"); return -1; } - if (getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT')) { + if (getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT') && ($qty > 0 || !getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) { $productChildrenNb = 0; if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) { $productChildrenNb = $product->hasFatherOrChild(1); @@ -1298,7 +1298,7 @@ class Expedition extends CommonObject } $tab[] = $linebatch; - if (getDolGlobalString("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", '0')) { + if (getDolGlobalString("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", '0') && ($linebatch->qty > 0 || !getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) { require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; $prod_batch = new Productbatch($this->db); $prod_batch->fetch($value['id_batch']); @@ -1796,6 +1796,9 @@ class Expedition extends CommonObject // We increment stock of batches // We use warehouse selected for each line foreach ($lotArray as $lot) { + if (empty($lot->qty)) { + continue; + } $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, (string) $lot->batch, '', 0, '', 0, (empty($obj->iskit) ? 1 : 0)); // Price is set to 0, because we don't want to see WAP changed if ($result < 0) { $error++;