diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f8b71082b21..fc2988a813e 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4687,7 +4687,7 @@ class Product extends CommonObject * @return int < 0 if KO, > 0 if OK * @see load_virtual_stock(), loadBatchInfo() */ - public function load_stock($option = '') + public function load_stock($option = '', $includedraftpoforvirtual = null) { // phpcs:enable global $conf; @@ -4740,7 +4740,7 @@ class Product extends CommonObject $this->db->free($result); if (!preg_match('/novirtual/', $option)) { - $this->load_virtual_stock(); // This also load stats_commande_fournisseur, ... + $this->load_virtual_stock($includedraftpoforvirtual); // This also load stats_commande_fournisseur, ... } return 1; @@ -4761,7 +4761,7 @@ class Product extends CommonObject * @return int < 0 if KO, > 0 if OK * @see load_stock(), loadBatchInfo() */ - public function load_virtual_stock() + public function load_virtual_stock($includedraftpoforvirtual = null) { // phpcs:enable global $conf, $hookmanager, $action; @@ -4793,19 +4793,25 @@ class Product extends CommonObject } if (!empty($conf->fournisseur->enabled)) { - $result = $this->load_stats_commande_fournisseur(0, '1,2,3,4', 1); + $filterStatus = '1,2,3,4'; + if (isset($includedraftpoforvirtual)) $filterStatus = '0,'.$filterStatus; + $result = $this->load_stats_commande_fournisseur(0, $filterStatus, 1); if ($result < 0) dol_print_error($this->db, $this->error); $stock_commande_fournisseur = $this->stats_commande_fournisseur['qty']; } if (!empty($conf->fournisseur->enabled) && empty($conf->reception->enabled)) { - $result = $this->load_stats_reception(0, '4', 1); + $filterStatus = '4'; + if (isset($includedraftpoforvirtual)) $filterStatus = '0,'.$filterStatus; + $result = $this->load_stats_reception(0, $filterStatus, 1); if ($result < 0) dol_print_error($this->db, $this->error); $stock_reception_fournisseur = $this->stats_reception['qty']; } if (!empty($conf->fournisseur->enabled) && !empty($conf->reception->enabled)) { - $result = $this->load_stats_reception(0, '4', 1); // Use same tables than when module reception is not used. + $filterStatus = '4'; + if (isset($includedraftpoforvirtual)) $filterStatus = '0,'.$filterStatus; + $result = $this->load_stats_reception(0, $filterStatus, 1); // Use same tables than when module reception is not used. if ($result < 0) dol_print_error($this->db, $this->error); $stock_reception_fournisseur = $this->stats_reception['qty']; } @@ -4847,7 +4853,7 @@ class Product extends CommonObject $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('productdao')); - $parameters = array('id'=>$this->id); + $parameters = array('id'=>$this->id, 'includedraftpoforvirtual' => $includedraftpoforvirtual); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('loadvirtualstock', $parameters, $this, $action); if ($reshook > 0) $this->stock_theorique = $hookmanager->resArray['stock_theorique']; diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index ae5c936ef1e..feba2dbafcb 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -648,7 +648,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) { $prod->fetch($objp->rowid); - $prod->load_stock('warehouseopen, warehouseinternal'); + $prod->load_stock('warehouseopen, warehouseinternal', $draftchecked); // Multilangs if (!empty($conf->global->MAIN_MULTILANGS))