From 6fd172609302c44ba0171949938b0553c7a2d9ee Mon Sep 17 00:00:00 2001 From: antonin_tdj <50403308+ibuiv@users.noreply.github.com> Date: Tue, 27 Apr 2021 12:14:36 +0200 Subject: [PATCH] Fix Bug replenish + Auto Filter # Fix Replenish Calculation Bug + Auto Filter ## Environment * Version: 13 * URL(s): product/stock/replenish.php ## Configuration MultiCompany needed with Stock Sharing ON, 2 entities and 1 warehouse per entity **Entity A** * Options: don't share stocks with other entities * Warehouse : only 1 (WAR_A) * Stock : 1 product (PROD) Qty : 4 **Entity B :** * Options: don't share stocks with other entities * Warehouse : only 1 (WAR_B) * Stock : 1 product --the same-- (PROD) Qty : 17 **Product :** * Desired Stock : 20 * Alert : 10 **WAR_A :** * For the product * Desired Stock : 16 * Alert : 6 ## Fixed behavior : * Entity A -> Replenish * If WAR_A selected should show the product and fill with 12 the qty to order. Physical Stock (All) and Physical Stock (this warehouse) should be 4. * If no Warehouse selected show the product and fill with 12 (because only one warehouse seen by this entity) the qty to order. Physical Stock (All) should be 4. ## Actual behavior : * Entity A -> Replenish * The product isn't showed. * If I intentionally incrementes the Desired Stock value. The product will be shown with the good filter (Warehouse if desired stock has been incremented on the combination ProductDesired <-> Warehouse). The qty for the order are correct and the physical stock shown is correct. ## Conclusion : * 1 bug and 1 improvment **BUG** : The value of the stock taken to whether or not show the product line is wrong. It is considering the stock in warehouses not shared with the entity. **IMPROVMENT** : If only one Warehouse, take automatically the desired and alert values for this warehouse and not the general ones. --- htdocs/product/stock/replenish.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index c9109b348d6..ab95c29eadd 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -6,6 +6,7 @@ * Copyright (C) 2016 ATM Consulting * Copyright (C) 2019 Frédéric France * Copyright (C) 2021 Ferran Marcet + * Copyright (C) 2021 Antonin MARCHAL * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,6 +65,20 @@ $draftorder = GETPOST('draftorder', 'alpha'); $fourn_id = GETPOST('fourn_id', 'int'); $fk_supplier = GETPOST('fk_supplier', 'int'); $fk_entrepot = GETPOST('fk_entrepot', 'int'); + +//MultiCompany : If only 1 Warehouse is visible, filter will automatically be set to it. +if ($fk_entrepot == "-1" && !empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED)) { + global $mc; + $visibleWarehousesEntities = $conf->entity; + if (isset($mc->sharings['stock']) && !empty($mc->sharings['stock'])) { + $visibleWarehousesEntities .= "," . implode(",", $mc->sharings['stock']); + } + $resWar = $db->query ("SELECT rowid FROM " . MAIN_DB_PREFIX . "entrepot WHERE entity IN (" . $db->sanitize($visibleWarehousesEntities) .")"); + if($db->num_rows($resWar) == 1){ + $fk_entrepot = $db->fetch_object($resWar)->rowid; + } +}; + $texte = ''; $sortfield = GETPOST('sortfield', 'aZ09comma'); @@ -324,8 +339,8 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N $sql .= $hookmanager->resPrint; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot AS ent ON s.fk_entrepot = ent.rowid AND ent.entity IN('.getEntity('stock').')'; +$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot AS ent ON ent.entity IN('.getEntity('stock').')'; +$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product AND s.fk_entrepot = ent.rowid'; if ($fk_supplier > 0) { $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price pfp ON (pfp.fk_product = p.rowid AND pfp.fk_soc = '.$fk_supplier.')'; }