From e44c3a46e144ef06ee36e182468dbedccb2a8732 Mon Sep 17 00:00:00 2001 From: xgerhard Date: Tue, 5 Oct 2021 00:25:52 +0200 Subject: [PATCH] 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);