Optimize load_stock and load_stock_virtual
This commit is contained in:
parent
c6371060d0
commit
39bc4d5f02
@ -716,7 +716,7 @@ if ($resql)
|
|||||||
// Get local and virtual stock and store it into cache
|
// Get local and virtual stock and store it into cache
|
||||||
if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
|
if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
|
||||||
$generic_product->load_stock();
|
$generic_product->load_stock();
|
||||||
$generic_product->load_virtual_stock();
|
//$generic_product->load_virtual_stock(); Already included into load_stock
|
||||||
$productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
|
$productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
|
||||||
$productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
|
$productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -109,8 +109,10 @@ class Product extends CommonObject
|
|||||||
var $localtax1_type;
|
var $localtax1_type;
|
||||||
var $localtax2_type;
|
var $localtax2_type;
|
||||||
|
|
||||||
//! Stock
|
//! Stock real
|
||||||
var $stock_reel;
|
var $stock_reel;
|
||||||
|
//! Stock virtual
|
||||||
|
var $stock_theorique;
|
||||||
//! Cost price
|
//! Cost price
|
||||||
var $cost_price;
|
var $cost_price;
|
||||||
//! Average price value for product entry into stock (PMP)
|
//! Average price value for product entry into stock (PMP)
|
||||||
@ -3341,14 +3343,16 @@ class Product extends CommonObject
|
|||||||
* Load information about stock of a product into stock_reel, stock_warehouse[] (including stock_warehouse[idwarehouse]->detail_batch for batch products)
|
* Load information about stock of a product into stock_reel, stock_warehouse[] (including stock_warehouse[idwarehouse]->detail_batch for batch products)
|
||||||
* This function need a lot of load. If you use it on list, use a cache to execute it one for each product id.
|
* This function need a lot of load. If you use it on list, use a cache to execute it one for each product id.
|
||||||
*
|
*
|
||||||
* @return int < 0 if KO, > 0 if OK
|
* @param string $option '', 'nobatch' = Do not load batch information, 'novirtual' = Do not load virtual stock
|
||||||
* @see load_virtual_stock, getBatchInfo
|
* @return int < 0 if KO, > 0 if OK
|
||||||
|
* @see load_virtual_stock, getBatchInfo
|
||||||
*/
|
*/
|
||||||
function load_stock()
|
function load_stock($option='')
|
||||||
{
|
{
|
||||||
$this->stock_reel = 0;
|
$this->stock_reel = 0;
|
||||||
$this->stock_warehouse = array();
|
$this->stock_warehouse = array();
|
||||||
|
$this->stock_theorique = 0;
|
||||||
|
|
||||||
$sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot";
|
$sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."entrepot as w";
|
$sql.= ", ".MAIN_DB_PREFIX."entrepot as w";
|
||||||
@ -3370,14 +3374,17 @@ class Product extends CommonObject
|
|||||||
$this->stock_warehouse[$row->fk_entrepot] = new stdClass();
|
$this->stock_warehouse[$row->fk_entrepot] = new stdClass();
|
||||||
$this->stock_warehouse[$row->fk_entrepot]->real = $row->reel;
|
$this->stock_warehouse[$row->fk_entrepot]->real = $row->reel;
|
||||||
$this->stock_warehouse[$row->fk_entrepot]->id = $row->rowid;
|
$this->stock_warehouse[$row->fk_entrepot]->id = $row->rowid;
|
||||||
if ($this->hasbatch()) $this->stock_warehouse[$row->fk_entrepot]->detail_batch=Productbatch::findAll($this->db,$row->rowid,1);
|
if ((! preg_match('/nobatch/', $option)) && $this->hasbatch()) $this->stock_warehouse[$row->fk_entrepot]->detail_batch=Productbatch::findAll($this->db,$row->rowid,1);
|
||||||
$this->stock_reel+=$row->reel;
|
$this->stock_reel+=$row->reel;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->db->free($result);
|
$this->db->free($result);
|
||||||
|
|
||||||
$this->load_virtual_stock(); // This also load stats_commande_fournisseur, ...
|
if (! preg_match('/novirtual/', $option))
|
||||||
|
{
|
||||||
|
$this->load_virtual_stock(); // This also load stats_commande_fournisseur, ...
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -683,10 +683,10 @@ else
|
|||||||
|
|
||||||
if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) // To optimize call of load_stock
|
if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) // To optimize call of load_stock
|
||||||
{
|
{
|
||||||
if ($objp->fk_product_type != 1)
|
if ($objp->fk_product_type != 1) // Not a service
|
||||||
{
|
{
|
||||||
$product_static->id = $objp->rowid;
|
$product_static->id = $objp->rowid;
|
||||||
$product_static->load_stock();
|
$product_static->load_stock('nobatch'); // Load stock_reel + stock_warehouse + batch detail. This also call load_virtual_stock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user