From 2fd01d71cfd8ec3e46b8b1bb860a90aad8664e65 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Feb 2016 22:20:42 +0100 Subject: [PATCH] Fix #4548 Check on stock enough must be done according to warehouse --- htdocs/expedition/class/expedition.class.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 9ad2108519a..c885a03145d 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -856,13 +856,23 @@ class Expedition extends CommonObject return -1; } - if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) // FIXME Check is done for stock of product, it must be done for stock of product into warehouse if $entrepot_id defined + if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) { + // Check must be done for stock of product into warehouse if $entrepot_id defined $product=new Product($this->db); $result=$product->fetch($fk_product); - $product_type=$product->type; - if ($product_type == 0 && $product->stock_reel < $qty) + $product_type=$product->type; + if ($entrepot_id > 0) { + $product->load_stock(); + $product_stock = $product->stock_warehouse[$entrepot_id]->real; + } + else + { + $product_stock = $product->stock_reel; + } + + if ($product_type == 0 && $product_stock < $qty) { $this->error=$langs->trans('ErrorStockIsNotEnough'); $this->db->rollback();