details: https://code.openbravo.com/erp/devel/pi/rev/c4adf2ef3519 changeset: 32914:c4adf2ef3519 user: Atul Gaware <atul.gaware <at> openbravo.com> date: Thu Oct 26 22:43:25 2017 +0530 summary: Fixes Issue 37155:Wrong transaction's accounting entry when working with multicurrency doubtful debt
Use invoice currency for fact acct line instead of financial account transaction currency in case of doubtful debt posting details: https://code.openbravo.com/erp/devel/pi/rev/d0a5ddee9b68 changeset: 32915:d0a5ddee9b68 user: David Miguelez <david.miguelez <at> openbravo.com> date: Fri Nov 03 11:59:33 2017 +0100 summary: Related to Issue 37155. Fixes conversion rate at doc level for posting Reconciliations with Doubtful Debts * When creating a new DocLine for DoubfulDebts, use a DocReconciliationLine instance, which is a child of DocLine * Set the Transaction Id to the new DocLine * This will allow to retrieve the conversion at Document Level from the Transaction when calculating the amount paid * Added explanatory comments diffstat: src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java | 11 ++- src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java | 28 ++++++--- 2 files changed, 25 insertions(+), 14 deletions(-) diffs (104 lines): diff -r b4af0d833993 -r d0a5ddee9b68 src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java --- a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java Fri Nov 03 07:47:29 2017 +0100 +++ b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java Fri Nov 03 11:59:33 2017 +0100 @@ -570,15 +570,18 @@ as.m_C_Currency_ID, line, as, fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn); } if (line.getDoubtFulDebtAmount().signum() != 0) { + // For Doubtful Debts, the Currency of the Invoice must be used to convert the amounts, + // since the debt has been recognized with the Currency of the Invoice + String strcCurrencyId = invoice.getCurrency().getId(); BigDecimal doubtFulDebtAmount = convertAmount(line.getDoubtFulDebtAmount(), isReceipt, - DateAcct, TABLEID_Invoice, invoice.getId(), C_Currency_ID, as.m_C_Currency_ID, + DateAcct, TABLEID_Invoice, invoice.getId(), strcCurrencyId, as.m_C_Currency_ID, line, as, fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn, false); fact.createLine(line, getAccountBPartner(bpartnerId, as, true, false, true, conn), - C_Currency_ID, "", doubtFulDebtAmount.toString(), Fact_Acct_Group_ID, + strcCurrencyId, "", doubtFulDebtAmount.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); bpAmountConverted = bpAmountConverted.subtract(doubtFulDebtAmount); fact.createLine(line, getAccountBPartnerAllowanceForDoubtfulDebt(bpartnerId, as, conn), - this.C_Currency_ID, doubtFulDebtAmount.toString(), "", Fact_Acct_Group_ID2, + strcCurrencyId, doubtFulDebtAmount.toString(), "", Fact_Acct_Group_ID2, nextSeqNo(SeqNo), DocumentType, conn); // Assign expense to the dimensions of the invoice lines BigDecimal assignedAmount = BigDecimal.ZERO; @@ -607,7 +610,7 @@ lineDD, getAccountBPartnerBadDebt( (lineDD.m_C_BPartner_ID == null || lineDD.m_C_BPartner_ID.equals("")) ? bpartnerId - : lineDD.m_C_BPartner_ID, false, as, conn), this.C_Currency_ID, "", + : lineDD.m_C_BPartner_ID, false, as, conn), strcCurrencyId, "", lineAmount.toString(), Fact_Acct_Group_ID2, nextSeqNo(SeqNo), DocumentType, conn); assignedAmount = assignedAmount.add(lineAmount); } diff -r b4af0d833993 -r d0a5ddee9b68 src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java --- a/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java Fri Nov 03 07:47:29 2017 +0100 +++ b/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java Fri Nov 03 11:59:33 2017 +0100 @@ -915,15 +915,19 @@ as.m_C_Currency_ID, line, as, fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn); } if (line.getDoubtFulDebtAmount().signum() != 0) { + // For Doubtful Debts, the Currency of the Invoice must be used to convert the amounts, + // since the debt has been recognized with the Currency of the Invoice + + String strcCurrencyId = invoice.getCurrency().getId(); BigDecimal doubtFulDebtAmount = convertAmount(line.getDoubtFulDebtAmount(), isReceipt, - DateAcct, TABLEID_Invoice, invoice.getId(), C_Currency_ID, as.m_C_Currency_ID, line, + DateAcct, TABLEID_Invoice, invoice.getId(), strcCurrencyId, as.m_C_Currency_ID, line, as, fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn, false); fact.createLine(line, getAccountBPartner(bpartnerId, as, true, false, true, conn), - C_Currency_ID, "", doubtFulDebtAmount.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), - DocumentType, conn); + strcCurrencyId, "", doubtFulDebtAmount.toString(), Fact_Acct_Group_ID, + nextSeqNo(SeqNo), DocumentType, conn); bpAmountConverted = bpAmountConverted.subtract(doubtFulDebtAmount); fact.createLine(line, getAccountBPartnerAllowanceForDoubtfulDebt(bpartnerId, as, conn), - this.C_Currency_ID, doubtFulDebtAmount.toString(), "", Fact_Acct_Group_ID2, + strcCurrencyId, doubtFulDebtAmount.toString(), "", Fact_Acct_Group_ID2, nextSeqNo(SeqNo), DocumentType, conn); // Assign expense to the dimensions of the invoice lines BigDecimal assignedAmount = BigDecimal.ZERO; @@ -935,7 +939,8 @@ if (j == data.length - 1) { lineAmount = doubtFulDebtAmount.subtract(assignedAmount); } - DocLine lineDD = new DocLine(DocumentType, Record_ID, ""); + DocLine_FINReconciliation lineDD = new DocLine_FINReconciliation(DocumentType, Record_ID, + ""); lineDD.m_A_Asset_ID = data[j].aAssetId; lineDD.m_M_Product_ID = data[j].mProductId; lineDD.m_C_Project_ID = data[j].cProjectId; @@ -947,11 +952,14 @@ lineDD.m_User1_ID = data[j].user1id; lineDD.m_User2_ID = data[j].user2id; lineDD.m_AD_Org_ID = data[j].adOrgId; + // Set the related financial account, so the Conversion Rate at Doc Level can be retrieved + // from it + lineDD.setFinFinAccTransactionId(line.getFinFinAccTransactionId()); fact.createLine( lineDD, getAccountBPartnerBadDebt((lineDD.m_C_BPartner_ID == null || lineDD.m_C_BPartner_ID .equals("")) ? bpartnerId : lineDD.m_C_BPartner_ID, false, as, conn), - this.C_Currency_ID, "", lineAmount.toString(), Fact_Acct_Group_ID2, nextSeqNo(SeqNo), + strcCurrencyId, "", lineAmount.toString(), Fact_Acct_Group_ID2, nextSeqNo(SeqNo), DocumentType, conn); assignedAmount = assignedAmount.add(lineAmount); } @@ -974,12 +982,12 @@ Account accountIDPrePayment = getAccountBPartner(bpartnerId, as, isReceipt, true, conn); if (!StringUtils.equals(accountIDReceivablesNo.getAccount_ID(), accountIDPrePayment.getAccount_ID())) { - fact.createLine(line2, accountIDReceivablesNo, - paymentCurrency.getId(), !isReceipt ? bpAmountConverted.toString() : "", + fact.createLine(line2, accountIDReceivablesNo, paymentCurrency.getId(), + !isReceipt ? bpAmountConverted.toString() : "", isReceipt ? bpAmountConverted.toString() : "", Fact_Acct_Group_ID2, nextSeqNo(SeqNo), DocumentType, line2.m_DateAcct, null, conn); - fact.createLine(line2, accountIDPrePayment, - paymentCurrency.getId(), isReceipt ? bpAmountConverted.toString() : "", + fact.createLine(line2, accountIDPrePayment, paymentCurrency.getId(), + isReceipt ? bpAmountConverted.toString() : "", !isReceipt ? bpAmountConverted.toString() : "", Fact_Acct_Group_ID2, nextSeqNo(SeqNo), DocumentType, line2.m_DateAcct, null, conn); } ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits