This commit is contained in:
Laurent Destailleur 2020-06-20 16:09:53 +02:00
parent ccc55dcb1e
commit fe1f88d2ac

View File

@ -475,10 +475,12 @@ class MouvementStock extends CommonObject
$newpmp = 0; $newpmp = 0;
if (!$error) if (!$error)
{ {
if ($type == 0 || $type == 3)
{
// After a stock increase
// Note: PMP is calculated on stock input only (type of movement = 0 or 3). If type == 0 or 3, qty should be > 0. // Note: PMP is calculated on stock input only (type of movement = 0 or 3). If type == 0 or 3, qty should be > 0.
// Note: Price should always be >0 or 0. PMP should be always >0 (calculated on input) // Note: Price should always be >0 or 0. PMP should be always >0 (calculated on input)
if (($type == 0 || $type == 3) && $price > 0) if ($price > 0 || (! empty($conf->global->STOCK_UPDATE_AWP_EVEN_WHEN_ENTRY_PRICE_IS_NULL) && $price ==0)) {
{
$oldqtytouse = ($oldqty >= 0 ? $oldqty : 0); $oldqtytouse = ($oldqty >= 0 ? $oldqty : 0);
// We make a test on oldpmp>0 to avoid to use normal rule on old data with no pmp field defined // We make a test on oldpmp>0 to avoid to use normal rule on old data with no pmp field defined
if ($oldpmp > 0) $newpmp = price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty), 'MU'); if ($oldpmp > 0) $newpmp = price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty), 'MU');
@ -489,6 +491,9 @@ class MouvementStock extends CommonObject
//print "oldqtytouse=".$oldqtytouse." oldpmp=".$oldpmp." oldqtywarehousetouse=".$oldqtywarehousetouse." "; //print "oldqtytouse=".$oldqtytouse." oldpmp=".$oldpmp." oldqtywarehousetouse=".$oldqtywarehousetouse." ";
//print "qty=".$qty." newpmp=".$newpmp; //print "qty=".$qty." newpmp=".$newpmp;
//exit; //exit;
} else {
$newpmp = $oldpmp;
}
} }
elseif ($type == 1 || $type == 2) elseif ($type == 1 || $type == 2)
{ {
@ -497,6 +502,7 @@ class MouvementStock extends CommonObject
} }
else else
{ {
// Type of movement unknown
$newpmp = $oldpmp; $newpmp = $oldpmp;
} }
} }