Fix bad recalculation of cost price of production of a product
This commit is contained in:
parent
159628be56
commit
ebd7605545
@ -399,7 +399,7 @@ ActionAvailableOnVariantProductOnly=Action only available on the variant of prod
|
|||||||
ProductsPricePerCustomer=Product prices per customers
|
ProductsPricePerCustomer=Product prices per customers
|
||||||
ProductSupplierExtraFields=Additional Attributes (Supplier Prices)
|
ProductSupplierExtraFields=Additional Attributes (Supplier Prices)
|
||||||
DeleteLinkedProduct=Delete the child product linked to the combination
|
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
|
PMPValue=Weighted average price
|
||||||
PMPValueShort=WAP
|
PMPValueShort=WAP
|
||||||
mandatoryperiod=Mandatory periods
|
mandatoryperiod=Mandatory periods
|
||||||
|
|||||||
@ -802,6 +802,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
|
|
||||||
// Lines to consume
|
// 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)) {
|
if (!empty($object->lines)) {
|
||||||
$nblinetoconsume = 0;
|
$nblinetoconsume = 0;
|
||||||
foreach ($object->lines as $line) {
|
foreach ($object->lines as $line) {
|
||||||
@ -820,7 +822,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
$linecost = price2num($tmpproduct->pmp, 'MT');
|
$linecost = price2num($tmpproduct->pmp, 'MT');
|
||||||
|
|
||||||
if ($object->qty > 0) {
|
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);
|
$costprice = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
|
||||||
if (empty($costprice)) {
|
if (empty($costprice)) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
|
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;
|
$costprice = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$linecost = price2num(($line->qty * $costprice) / $object->qty, 'MT');
|
$linecost = price2num(($line->qty * $costprice) / $object->qty, 'MT'); // price for line for all quantities
|
||||||
$bomcost += $linecost;
|
$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);
|
$arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
|
||||||
$alreadyconsumed = 0;
|
$alreadyconsumed = 0;
|
||||||
foreach ($arrayoflines as $line2) {
|
foreach ($arrayoflines as $line2) {
|
||||||
@ -1111,7 +1112,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
print '<td>'.$langs->trans("Product").'</td>';
|
print '<td>'.$langs->trans("Product").'</td>';
|
||||||
print '<td class="right">'.$langs->trans("Qty").'</td>';
|
print '<td class="right">'.$langs->trans("Qty").'</td>';
|
||||||
if ($permissiontoupdatecost) {
|
if ($permissiontoupdatecost) {
|
||||||
if (empty($bomcost)) {
|
if (empty($bomcostupdated)) {
|
||||||
print '<td class="right">'.$form->textwithpicto($langs->trans("UnitCost"), $langs->trans("AmountUsedToUpdateWAP")).'</td>';
|
print '<td class="right">'.$form->textwithpicto($langs->trans("UnitCost"), $langs->trans("AmountUsedToUpdateWAP")).'</td>';
|
||||||
} else {
|
} else {
|
||||||
print '<td class="right">'.$form->textwithpicto($langs->trans("ManufacturingPrice"), $langs->trans("AmountUsedToUpdateWAP")).'</td>';
|
print '<td class="right">'.$form->textwithpicto($langs->trans("ManufacturingPrice"), $langs->trans("AmountUsedToUpdateWAP")).'</td>';
|
||||||
@ -1199,17 +1200,25 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
if ($permissiontoupdatecost) {
|
if ($permissiontoupdatecost) {
|
||||||
// Defined $manufacturingcost
|
// Defined $manufacturingcost
|
||||||
$manufacturingcost = 0;
|
$manufacturingcost = 0;
|
||||||
if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble"
|
$manufacturingcostsrc = '';
|
||||||
$manufacturingcost = $bomcost;
|
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)) {
|
if (empty($manufacturingcost)) {
|
||||||
$manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
|
$manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
|
||||||
|
$manufacturingcostsrc = $langs->trans("CostPrice");
|
||||||
}
|
}
|
||||||
if (empty($manufacturingcost)) {
|
if (empty($manufacturingcost)) {
|
||||||
$manufacturingcost = price2num($tmpproduct->pmp, 'MU');
|
$manufacturingcost = price2num($tmpproduct->pmp, 'MU');
|
||||||
|
$manufacturingcostsrc = $langs->trans("PMPValue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<td class="right nowraponall">';
|
print '<td class="right nowraponall" title="'.dol_escape_htmltag($manufacturingcostsrc).'">';
|
||||||
if ($manufacturingcost) {
|
if ($manufacturingcost) {
|
||||||
print price($manufacturingcost);
|
print price($manufacturingcost);
|
||||||
}
|
}
|
||||||
@ -1306,19 +1315,27 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
if ($permissiontoupdatecost) {
|
if ($permissiontoupdatecost) {
|
||||||
// Defined $manufacturingcost
|
// Defined $manufacturingcost
|
||||||
$manufacturingcost = 0;
|
$manufacturingcost = 0;
|
||||||
if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble"
|
$manufacturingcostsrc = '';
|
||||||
$manufacturingcost = $bomcost;
|
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)) {
|
if (empty($manufacturingcost)) {
|
||||||
$manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
|
$manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
|
||||||
|
$manufacturingcostsrc = $langs->trans("CostPrice");
|
||||||
}
|
}
|
||||||
if (empty($manufacturingcost)) {
|
if (empty($manufacturingcost)) {
|
||||||
$manufacturingcost = price2num($tmpproduct->pmp, 'MU');
|
$manufacturingcost = price2num($tmpproduct->pmp, 'MU');
|
||||||
|
$manufacturingcostsrc = $langs->trans("PMPValue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
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) : ''));
|
$preselected = (GETPOSTISSET('pricetoproduce-'.$line->id.'-'.$i) ? GETPOST('pricetoproduce-'.$line->id.'-'.$i) : ($manufacturingcost ? price($manufacturingcost) : ''));
|
||||||
print '<td class="right"><input type="text" class="width50 right" name="pricetoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
|
print '<td class="right"><input type="text" class="width75 right" name="pricetoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
|
||||||
} else {
|
} else {
|
||||||
print '<td><input type="hidden" class="width50 right" name="pricetoproduce-'.$line->id.'-'.$i.'" value="'.($manufacturingcost ? $manufacturingcost : '').'"></td>';
|
print '<td><input type="hidden" class="width50 right" name="pricetoproduce-'.$line->id.'-'.$i.'" value="'.($manufacturingcost ? $manufacturingcost : '').'"></td>';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user