From bbdb20146588f76c4cb9e0a20b3c948b79eb03dc Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 18 Dec 2013 15:10:21 +0800 Subject: [PATCH] 1003628 Incorrect Landed Cost Allocation calculation. Fixed issue with currency conversion and rounding. --- .../src/org/compiere/acct/Doc_Invoice.java | 22 +++++++++---------- .../src/org/compiere/model/MInvoiceLine.java | 12 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java b/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java index c0aff41f46..ef2e6076ed 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java @@ -852,16 +852,7 @@ public class Doc_Invoice extends Doc if (X_M_Cost.COSTINGMETHOD_AverageInvoice.equals(costingMethod) || X_M_Cost.COSTINGMETHOD_AveragePO.equals(costingMethod)) { - // Convert to AcctCurrency - BigDecimal allocationAmt = lca.getAmt(); - if (getC_Currency_ID() != as.getC_Currency_ID()) - allocationAmt = MConversionRate.convert(getCtx(), allocationAmt, - getC_Currency_ID(), as.getC_Currency_ID(), - getDateAcct(), getC_ConversionType_ID(), - getAD_Client_ID(), getAD_Org_ID()); - if (allocationAmt.scale() > as.getCostingPrecision()) - allocationAmt = allocationAmt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP); - + BigDecimal allocationAmt = lca.getAmt(); BigDecimal estimatedAmt = BigDecimal.ZERO; if (lca.getM_InOutLine_ID() > 0) { @@ -921,11 +912,20 @@ public class Doc_Invoice extends Doc boolean zeroQty = false; try { savepoint = trx.setSavepoint(null); + BigDecimal costDetailAmt = costAdjustmentAmt; + //convert to accounting schema currency + if (getC_Currency_ID() != as.getC_Currency_ID()) + costDetailAmt = MConversionRate.convert(getCtx(), costDetailAmt, + getC_Currency_ID(), as.getC_Currency_ID(), + getDateAcct(), getC_ConversionType_ID(), + getAD_Client_ID(), getAD_Org_ID()); + if (costDetailAmt.scale() > as.getCostingPrecision()) + costDetailAmt = costDetailAmt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP); if (!MCostDetail.createInvoice(as, lca.getAD_Org_ID(), lca.getM_Product_ID(), lca.getM_AttributeSetInstance_ID(), C_InvoiceLine_ID, lca.getM_CostElement_ID(), - costAdjustmentAmt, lca.getQty(), + costDetailAmt, lca.getQty(), desc, getTrxName())) { throw new RuntimeException("Failed to create cost detail record."); } diff --git a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java index ca189a257f..83380f904e 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java @@ -1096,9 +1096,9 @@ public class MInvoiceLine extends X_C_InvoiceLine // end MZ if (base.signum() != 0) { - BigDecimal result = getLineNetAmt().multiply(base); - result = result.divide(total, BigDecimal.ROUND_HALF_UP); - lca.setAmt(result.doubleValue(), getPrecision()); + double result = getLineNetAmt().multiply(base).doubleValue(); + result /= total.doubleValue(); + lca.setAmt(result, getPrecision()); } if (!lca.save()){ msgreturn = new StringBuilder("Cannot save line Allocation = ").append(lca); @@ -1221,9 +1221,9 @@ public class MInvoiceLine extends X_C_InvoiceLine // end MZ if (base.signum() != 0) { - BigDecimal result = getLineNetAmt().multiply(base); - result = result.divide(total, BigDecimal.ROUND_HALF_UP); - lca.setAmt(result.doubleValue(), getPrecision()); + double result = getLineNetAmt().multiply(base).doubleValue(); + result /= total.doubleValue(); + lca.setAmt(result, getPrecision()); } if (!lca.save()){ msgreturn = new StringBuilder("Cannot save line Allocation = ").append(lca);