diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang
index ae199f4136b..b8f242652a1 100644
--- a/htdocs/langs/en_US/products.lang
+++ b/htdocs/langs/en_US/products.lang
@@ -397,6 +397,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
PMPValue=Weighted average price
PMPValueShort=WAP
DefaultBOM=Default BOM
diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php
index 3dccebf9549..84dab109b91 100644
--- a/htdocs/mrp/mo_production.php
+++ b/htdocs/mrp/mo_production.php
@@ -38,7 +38,7 @@ dol_include_once('/bom/class/bom.class.php');
dol_include_once('/mrp/lib/mrp_mo.lib.php');
// Load translation files required by the page
-$langs->loadLangs(array("mrp", "stocks", "other", "productbatch"));
+$langs->loadLangs(array("mrp", "stocks", "other", "product", "productbatch"));
// Get parameters
$id = GETPOST('id', 'int');
@@ -691,6 +691,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$bom = new Bom($db);
$res = $bom->fetch($object->fk_bom);
if ($res > 0) {
+ $bom->calculateCosts();
$bomcost = $bom->unit_cost;
}
}
@@ -818,6 +819,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}
}
+ $bomcost = price2num($bomcost, 'MU');
+
$arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
$alreadyconsumed = 0;
foreach ($arrayoflines as $line2) {
@@ -1006,9 +1009,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '
'.$langs->trans("Qty").' | ';
if ($permissiontoupdatecost) {
if (empty($bomcost)) {
- print ''.$langs->trans("PMPValue").' | ';
+ print ''.$form->textwithpicto($langs->trans("UnitCost"), $langs->trans("AmountUsedToUpdateWAP")).' | ';
} else {
- print ''.$langs->trans("UnitCost").' | ';
+ print ''.$form->textwithpicto($langs->trans("ManufacturingPrice"), $langs->trans("AmountUsedToUpdateWAP")).' | ';
}
}
print ''.$langs->trans("QtyAlreadyProduced").' | ';
@@ -1073,10 +1076,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$tmpproduct = new Product($db);
$tmpproduct->fetch($line->fk_product);
- if (empty($bomcost)) {
- $bomcost = $tmpproduct->pmp;
- }
-
$arrayoflines = $object->fetchLinesLinked('produced', $line->id);
$alreadyproduced = 0;
foreach ($arrayoflines as $line2) {
@@ -1095,8 +1094,19 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '';
print ''.$line->qty.' | ';
if ($permissiontoupdatecost) {
+ // Defined $manufacturingcost
+ $manufacturingcost = $bomcost;
+ if (empty($manufacturingcost)) {
+ $manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
+ }
+ if (empty($manufacturingcost)) {
+ $manufacturingcost = price2num($tmpproduct->pmp, 'MU');
+ }
+
print '';
- print price($bomcost);
+ if ($manufacturingcost) {
+ print price($manufacturingcost);
+ }
print ' | ';
}
print '';
@@ -1188,11 +1198,20 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}
print ' | | ';
if ($permissiontoupdatecost) {
+ // Defined $manufacturingcost
+ $manufacturingcost = $bomcost;
+ if (empty($manufacturingcost)) {
+ $manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
+ }
+ if (empty($manufacturingcost)) {
+ $manufacturingcost = price2num($tmpproduct->pmp, 'MU');
+ }
+
if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
- $preselected = (GETPOSTISSET('pricetoproduce-'.$line->id.'-'.$i) ? GETPOST('pricetoproduce-'.$line->id.'-'.$i) : price($bomcost));
+ $preselected = (GETPOSTISSET('pricetoproduce-'.$line->id.'-'.$i) ? GETPOST('pricetoproduce-'.$line->id.'-'.$i) : price($manufacturingcost));
print ' | ';
} else {
- print ' | ';
+ print ' | ';
}
}
print ' | ';