From bbdb20146588f76c4cb9e0a20b3c948b79eb03dc Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 18 Dec 2013 15:10:21 +0800 Subject: [PATCH 1/3] 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); From cd583057616758df8678410c31784f5d01141935 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 18 Dec 2013 16:36:04 +0800 Subject: [PATCH 2/3] 1003628 Incorrect Landed Cost Allocation calculation. Fixed rounding issue. --- .../src/org/compiere/model/MInvoiceLine.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java index 93dff64ddf..9809c9e095 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java @@ -1089,9 +1089,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); @@ -1212,9 +1212,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); From 9dff6966e0faee153681060ea292c6e40cd952b6 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Thu, 19 Dec 2013 16:59:29 +0800 Subject: [PATCH 3/3] 1003576 CLOSE TAB WARINING SHOULDN'T APPEAR WHEN SESSION IS KILLED. Peer review. --- .../WEB-INF/src/org/adempiere/webui/panel/TimeoutPanel.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/TimeoutPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/TimeoutPanel.java index fe734c421b..c590d0fc03 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/TimeoutPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/TimeoutPanel.java @@ -21,6 +21,7 @@ import org.zkoss.zhtml.Script; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.util.Clients; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Center; import org.zkoss.zul.Div; @@ -143,6 +144,7 @@ public class TimeoutPanel extends Window implements timer.stop(); SessionManager.logoutSession(); Executions.sendRedirect("/index.zul"); + Clients.confirmClose(null); } } }