NEW Add Hook for adapting virtual stock in replenish screen (#37290)

* Add Hook for adapting virtual stock in replenish screen 

Currently it is only possible to hook in the loadvirtualstock hook to adapt the virtual stock by external modules. The newer version of the replenish screen doesn't use this hook anymore (by loading stock from product object) as it now uses faster sql queries. Therefore the external module cannot adapt this area and there is an missmatch of the view in replenish.php and the stock tab of the product.

* fix phan warning
This commit is contained in:
splohmer 2026-02-23 01:03:21 +01:00 committed by GitHub
parent 0b34a66fe6
commit 00a64df8e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -517,16 +517,23 @@ if ($usevirtualstock) {
$sqlProductionToProduce = '0';
}
$parameters = array();
$sqlHookVirtualStock = "0";
$reshook = $hookmanager->executeHooks('printFieldListHavingVirtualStock', $parameters); // Note that $action and $object may have been modified by hook
if (!empty($hookmanager->resPrint)) {
$sqlHookVirtualStock = $hookmanager->resPrint;
}
$sql .= ' HAVING (';
$sql .= " (" . $sqldesiredtock . " >= 0 AND (" . $sqldesiredtock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ')';
$sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . ")))";
$sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . ") + ".$sqlHookVirtualStock."))";
$sql .= ' OR';
if ($includeproductswithoutdesiredqty == 'on') {
$sql .= " ((" . $sqlalertstock . " >= 0 OR " . $sqlalertstock . " IS NULL) AND (" . $db->ifsql($sqlalertstock . " IS NULL", "0", $sqlalertstock) . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ")";
} else {
$sql .= " (" . $sqlalertstock . " >= 0 AND (" . $sqlalertstock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ')';
}
$sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . ")))";
$sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . ") + ".$sqlHookVirtualStock."))";
$sql .= ")";
if (getDolGlobalString('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE') && $fk_entrepot > 0) {
$sql .= " AND (";
@ -540,7 +547,7 @@ if ($usevirtualstock) {
} else {
$sql .= $sqlalertstock . " >= 0 AND (" . $sqlalertstock . " > SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ")";
}
$sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . "))";
$sql .= " - (" . $sqlCommandesCli . " - " . $sqlExpeditionsCli . ") + (" . $sqlCommandesFourn . " - " . $sqlReceptionFourn . ") + (" . $sqlProductionToProduce . " - " . $sqlProductionToConsume . ") + ".$sqlHookVirtualStock.")";
$sql .= ")";
$alertchecked = 'checked';
}