From e44c3a46e144ef06ee36e182468dbedccb2a8732 Mon Sep 17 00:00:00 2001 From: xgerhard Date: Tue, 5 Oct 2021 00:25:52 +0200 Subject: [PATCH 1/2] Fix #18895 Fix negative stock correction If people use a negative number as input, I think we can assume they want to delete units. It will now set the movement to 1 if the number is negative and 'add' was selected. For each negative number we now multiply this number by -1, to make it a positive number again. --- htdocs/product/class/product.class.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 1109c93fad9..eebd5a35c4f 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5129,6 +5129,13 @@ class Product extends CommonObject include_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; + if ($nbpiece < 0) { + if (!$movement) { + $movement = 1; + } + $nbpiece *= -1; + } + $op[0] = "+".trim($nbpiece); $op[1] = "-".trim($nbpiece); @@ -5176,6 +5183,13 @@ class Product extends CommonObject include_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; + if ($nbpiece < 0) { + if (!$movement) { + $movement = 1; + } + $nbpiece *= -1; + } + $op[0] = "+".trim($nbpiece); $op[1] = "-".trim($nbpiece); From e85a0c54cc8f9e9f9c7f1f079954433537966f9e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 5 Oct 2021 18:43:35 +0200 Subject: [PATCH 2/2] Update product.class.php --- htdocs/product/class/product.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index eebd5a35c4f..3be832dcea3 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5111,7 +5111,7 @@ class Product extends CommonObject * * @param User $user user asking change * @param int $id_entrepot id of warehouse - * @param double $nbpiece nb of units + * @param double $nbpiece nb of units (should be always positive, use $movement to decide if we add or remove) * @param int $movement 0 = add, 1 = remove * @param string $label Label of stock movement * @param double $price Unit price HT of product, used to calculate average weighted price (PMP in french). If 0, average weighted price is not changed. @@ -5133,7 +5133,7 @@ class Product extends CommonObject if (!$movement) { $movement = 1; } - $nbpiece *= -1; + $nbpiece = abs($nbpiece); } $op[0] = "+".trim($nbpiece); @@ -5162,7 +5162,7 @@ class Product extends CommonObject * * @param User $user user asking change * @param int $id_entrepot id of warehouse - * @param double $nbpiece nb of units + * @param double $nbpiece nb of units (should be always positive, use $movement to decide if we add or remove) * @param int $movement 0 = add, 1 = remove * @param string $label Label of stock movement * @param double $price Price to use for stock eval @@ -5187,7 +5187,7 @@ class Product extends CommonObject if (!$movement) { $movement = 1; } - $nbpiece *= -1; + $nbpiece = abs($nbpiece); } $op[0] = "+".trim($nbpiece);