From da569ea8d4dc02aaa1b6158524958e692ab7d81a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 10 Dec 2013 19:39:28 +0100 Subject: [PATCH] Fix: Serious pb with loading stocks. If we use product->stock_reel or product->stock_warehoure[], we must call product->load_stock() after the product->fetch(). --- htdocs/expedition/shipment.php | 1 + htdocs/product/class/product.class.php | 8 +++++--- htdocs/product/stock/class/mouvementstock.class.php | 3 ++- htdocs/product/stock/product.php | 6 +++--- htdocs/webservices/server_productorservice.php | 3 +++ 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index 1e09cd47482..9d2c8da6351 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -495,6 +495,7 @@ if ($id > 0 || ! empty($ref)) { $product = new Product($db); $product->fetch($objp->fk_product); + $product->load_stock(); } if ($objp->fk_product > 0 && $type == 0 && ! empty($conf->stock->enabled)) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index aba63503731..6a94184d7c1 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1224,6 +1224,7 @@ class Product extends CommonObject $this->db->free($resql); + // multilangs if (! empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs(); @@ -1347,10 +1348,11 @@ class Product extends CommonObject } } - // We should not load stock at each fetch + // We should not load stock at each fetch. If someone need stock, he must call load_stock after fetch. //$res=$this->load_stock(); - - return $res; + //return $res; + + return 1; } else { diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 6e4ada58b34..2652c7c45bd 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -81,7 +81,8 @@ class MouvementStock dol_print_error('',"Failed to fetch product"); return -1; } - + $product->load_stock(); + // Define if we must make the stock change (If product type is a service or if stock is used also for services) $movestock=0; if ($product->type != 1 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock=1; diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 10ada810276..153356d969f 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -207,9 +207,9 @@ $formproduct=new FormProduct($db); if ($id > 0 || $ref) { $product = new Product($db); - if ($ref) $result = $product->fetch('',$ref); - if ($id > 0) $result = $product->fetch($id); - + $result = $product->fetch($id,$ref); + $product->load_stock(); + $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("",$langs->trans("CardProduct".$product->type),$help_url); diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index 22b4c66b97e..55de6300de9 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -333,8 +333,11 @@ function getProductOrService($authentication,$id='',$ref='',$ref_ext='') { $product=new Product($db); $result=$product->fetch($id,$ref,$ref_ext); + if ($result > 0) { + $product->load_stock(); + $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output); $pdir = get_exdir($product->id,2) . $product->id ."/photos/"; $dir = $dir . '/'. $pdir;