From e87d1750415679b2556f961fedd0c2aa64775446 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 28 May 2021 09:57:21 +0200 Subject: [PATCH 1/3] Fix inventory/inventory.php --- htdocs/langs/en_US/stocks.lang | 1 + htdocs/product/inventory/inventory.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 93cf9e9e037..977aab588a2 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -255,3 +255,4 @@ MakeMovementsAndClose=Generate movements and close AutofillWithExpected=Fill real quantity with expected quantity ShowAllBatchByDefault=By default, show batch details on product "stock" tab CollapseBatchDetailHelp=You can set batch detail default display in stocks module configuration +FieldCannotBeNegative=Field "%s" cannot be negative \ No newline at end of file diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 2abc830eb7c..212f0404bd9 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -185,8 +185,11 @@ if ($action =='updateinventorylines' && $permissiontoadd) { if (GETPOST("id_".$lineid, 'alpha') != '') { // If a value was set ('0' or something else) $qtytoupdate = price2num(GETPOST("id_".$lineid, 'alpha'), 'MS'); - $result = $inventoryline->fetch($lineid); + if ($qtytoupdate < 0) { + $result = -1; + setEventMessages($langs->trans("FieldCannotBeNegative", $langs->transnoentitiesnoconv("RealQty")), null, 'errors'); + } if ($result > 0) { $inventoryline->qty_view = $qtytoupdate; $resultupdate = $inventoryline->update($user); @@ -251,7 +254,10 @@ if (empty($reshook)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); } - + if (GETPOST('qtytoadd') < 0) { + $error++; + setEventMessages($langs->trans("FieldCannotBeNegative", $langs->transnoentitiesnoconv("RealQty")), null, 'errors'); + } if (!$error && !empty($conf->productbatch->enabled)) { $tmpproduct = new Product($db); $result = $tmpproduct->fetch($fk_product); @@ -654,7 +660,7 @@ if ($object->id > 0) { // Real quantity print ''; if ($object->status == $object::STATUS_VALIDATED) { - $qty_view = GETPOST("id_".$obj->rowid) ? GETPOST("id_".$obj->rowid) : $obj->qty_view; + $qty_view = GETPOST("id_".$obj->rowid) && GETPOST("id_".$obj->rowid) >= 0 ? GETPOST("id_".$obj->rowid) : $obj->qty_view; $totalfound += price2num($qty_view, 'MS'); print ''; print ''; From 1136e7dec537e58c0c4d6503b97465ae22e9750a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 4 Jun 2021 11:57:59 +0200 Subject: [PATCH 2/3] Update inventory.php --- htdocs/product/inventory/inventory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 212f0404bd9..eee7217eef3 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -254,7 +254,7 @@ if (empty($reshook)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); } - if (GETPOST('qtytoadd') < 0) { + if (price2num(GETPOST('qtytoadd'), 'MS') < 0) { $error++; setEventMessages($langs->trans("FieldCannotBeNegative", $langs->transnoentitiesnoconv("RealQty")), null, 'errors'); } From e26f0f155fdcc5c51e2c9a2ad9bc45ef7f5ec1c1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 4 Jun 2021 12:00:54 +0200 Subject: [PATCH 3/3] Update inventory.php --- htdocs/product/inventory/inventory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index eee7217eef3..644e7ba2025 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -660,7 +660,7 @@ if ($object->id > 0) { // Real quantity print ''; if ($object->status == $object::STATUS_VALIDATED) { - $qty_view = GETPOST("id_".$obj->rowid) && GETPOST("id_".$obj->rowid) >= 0 ? GETPOST("id_".$obj->rowid) : $obj->qty_view; + $qty_view = GETPOST("id_".$obj->rowid) && price2num(GETPOST("id_".$obj->rowid), 'MS') >= 0 ? GETPOST("id_".$obj->rowid) : $obj->qty_view; $totalfound += price2num($qty_view, 'MS'); print ''; print '';