Update expedition.class.php (#39314)
* 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 <sylvain.legrand@infras.fr>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
parent
58c951afd6
commit
3c02819090
1 changed files with 6 additions and 3 deletions
|
|
@ -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++;
|
||||
|
|
|
|||
Loading…
Reference in a new issue