diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index a0a3f4e588d..38f57cda105 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -399,7 +399,7 @@ ActionAvailableOnVariantProductOnly=Action only available on the variant of prod ProductsPricePerCustomer=Product prices per customers ProductSupplierExtraFields=Additional Attributes (Supplier Prices) DeleteLinkedProduct=Delete the child product linked to the combination -AmountUsedToUpdateWAP=Amount to use to update the Weighted Average Price +AmountUsedToUpdateWAP=Unit amount to use to update the Weighted Average Price PMPValue=Weighted average price PMPValueShort=WAP mandatoryperiod=Mandatory periods diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index fb0930deede..c86fcb1f926 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -802,6 +802,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Lines to consume + $bomcostupdated = 0; // We will recalculate the unitary cost to produce a product using the real "products to consume into MO" + if (!empty($object->lines)) { $nblinetoconsume = 0; foreach ($object->lines as $line) { @@ -820,7 +822,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $linecost = price2num($tmpproduct->pmp, 'MT'); if ($object->qty > 0) { - // add free consume line cost to bomcost + // add free consume line cost to $bomcostupdated $costprice = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp); if (empty($costprice)) { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; @@ -831,12 +833,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $costprice = 0; } } - $linecost = price2num(($line->qty * $costprice) / $object->qty, 'MT'); - $bomcost += $linecost; + $linecost = price2num(($line->qty * $costprice) / $object->qty, 'MT'); // price for line for all quantities + $bomcostupdated += price2num(($line->qty * $costprice) / $object->qty, 'MU'); // same but with full accuracy } - $bomcost = price2num($bomcost, 'MU'); - + $bomcostupdated = price2num($bomcostupdated, 'MU'); $arrayoflines = $object->fetchLinesLinked('consumed', $line->id); $alreadyconsumed = 0; foreach ($arrayoflines as $line2) { @@ -1111,7 +1112,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.$langs->trans("Product").''; print ''.$langs->trans("Qty").''; if ($permissiontoupdatecost) { - if (empty($bomcost)) { + if (empty($bomcostupdated)) { print ''.$form->textwithpicto($langs->trans("UnitCost"), $langs->trans("AmountUsedToUpdateWAP")).''; } else { print ''.$form->textwithpicto($langs->trans("ManufacturingPrice"), $langs->trans("AmountUsedToUpdateWAP")).''; @@ -1199,17 +1200,25 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($permissiontoupdatecost) { // Defined $manufacturingcost $manufacturingcost = 0; - if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble" - $manufacturingcost = $bomcost; + $manufacturingcostsrc = ''; + if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble") + $manufacturingcost = $bomcostupdated; + $manufacturingcostsrc = $langs->trans("CalculatedFromProductsToConsume"); + if (empty($manufacturingcost)) { + $manufacturingcost = $bomcost; + $manufacturingcostsrc = $langs->trans("ValueFromBom"); + } if (empty($manufacturingcost)) { $manufacturingcost = price2num($tmpproduct->cost_price, 'MU'); + $manufacturingcostsrc = $langs->trans("CostPrice"); } if (empty($manufacturingcost)) { $manufacturingcost = price2num($tmpproduct->pmp, 'MU'); + $manufacturingcostsrc = $langs->trans("PMPValue"); } } - print ''; + print ''; if ($manufacturingcost) { print price($manufacturingcost); } @@ -1306,19 +1315,27 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($permissiontoupdatecost) { // Defined $manufacturingcost $manufacturingcost = 0; - if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble" - $manufacturingcost = $bomcost; + $manufacturingcostsrc = ''; + if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble") + $manufacturingcost = $bomcostupdated; + $manufacturingcostsrc = $langs->trans("CalculatedFromProductsToConsume"); + if (empty($manufacturingcost)) { + $manufacturingcost = $bomcost; + $manufacturingcostsrc = $langs->trans("ValueFromBom"); + } if (empty($manufacturingcost)) { $manufacturingcost = price2num($tmpproduct->cost_price, 'MU'); + $manufacturingcostsrc = $langs->trans("CostPrice"); } if (empty($manufacturingcost)) { $manufacturingcost = price2num($tmpproduct->pmp, 'MU'); + $manufacturingcostsrc = $langs->trans("PMPValue"); } } if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $preselected = (GETPOSTISSET('pricetoproduce-'.$line->id.'-'.$i) ? GETPOST('pricetoproduce-'.$line->id.'-'.$i) : ($manufacturingcost ? price($manufacturingcost) : '')); - print ''; + print ''; } else { print ''; }