From 263759c138c2f7f1ded9959fbf8f21cf12db6c90 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 14 Nov 2016 17:49:06 +0800 Subject: [PATCH] IDEMPIERE-3235 Posting error when currency rate is different between MR and PO. --- .../src/org/compiere/acct/Doc_MatchPO.java | 4 ++-- .../src/org/compiere/acct/Fact.java | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java b/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java index eafa8c67e2..9cb6f14d1f 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java @@ -202,7 +202,7 @@ public class Doc_MatchPO extends Doc if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID()) { MOrder order = m_oLine.getParent(); - Timestamp dateAcct = order.getDateAcct(); + Timestamp dateAcct = inOut.getDateAcct(); BigDecimal rate = MConversionRate.getRate( order.getC_Currency_ID(), as.getC_Currency_ID(), dateAcct, order.getC_ConversionType_ID(), @@ -236,7 +236,7 @@ public class Doc_MatchPO extends Doc if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID()) { MOrder order = m_oLine.getParent(); - Timestamp dateAcct = order.getDateAcct(); + Timestamp dateAcct = inOut.getDateAcct(); BigDecimal rate = MConversionRate.getRate( order.getC_Currency_ID(), as.getC_Currency_ID(), dateAcct, order.getC_ConversionType_ID(), diff --git a/org.adempiere.base/src/org/compiere/acct/Fact.java b/org.adempiere.base/src/org/compiere/acct/Fact.java index 4565ec1622..37026839f4 100644 --- a/org.adempiere.base/src/org/compiere/acct/Fact.java +++ b/org.adempiere.base/src/org/compiere/acct/Fact.java @@ -253,6 +253,18 @@ public final class Fact // No lines -> balanced if (m_lines.size() == 0 || m_doc.isMultiCurrency()) return true; + + // If there is more than 1 currency in fact lines, it is a multi currency doc + ArrayList list = new ArrayList(); + for (int i = 0; i < m_lines.size(); i++){ + FactLine line = (FactLine)m_lines.get(i); + if (line.getC_Currency_ID() > 0 && !list.contains(line.getC_Currency_ID())) + list.add(line.getC_Currency_ID()); + + } + if (list.size() > 1 ) + return true; + BigDecimal balance = getSourceBalance(); boolean retValue = balance.signum() == 0; if (retValue) { @@ -328,7 +340,17 @@ public final class Fact // No lines -> balanced if (m_lines.size() == 0 || m_doc.isMultiCurrency()) return true; - + + // If there is more than 1 currency in fact lines, it is a multi currency doc + ArrayList list = new ArrayList(); + for (int i = 0; i < m_lines.size(); i++){ + FactLine line = (FactLine)m_lines.get(i); + if (line.getC_Currency_ID() > 0 && !list.contains(line.getC_Currency_ID())) + list.add(line.getC_Currency_ID()); + } + if (list.size() > 1 ) + return true; + MAcctSchemaElement[] elements = m_acctSchema.getAcctSchemaElements(); // check all balancing segments for (int i = 0; i < elements.length; i++)