From 78309342a7fdbb70c4c76065200d2a464791ba6e Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 2 May 2018 12:26:06 +0200 Subject: [PATCH] IDEMPIERE-3702 Post if clearing is equal is not working on AP Payments AP2-140 --- .../src/org/compiere/acct/Doc_Payment.java | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Payment.java b/org.adempiere.base/src/org/compiere/acct/Doc_Payment.java index c888349eac..2d598d3b17 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Payment.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Payment.java @@ -116,14 +116,16 @@ public class Doc_Payment extends Doc return facts; } + FactLine dr = null; + FactLine cr = null; int AD_Org_ID = getBank_Org_ID(); // Bank Account Org if (getDocumentType().equals(DOCTYPE_ARReceipt)) { // Asset - FactLine fl = fact.createLine(null, getAccount(Doc.ACCTTYPE_BankInTransit, as), + dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_BankInTransit, as), getC_Currency_ID(), getAmount(), null); - if (fl != null && AD_Org_ID != 0) - fl.setAD_Org_ID(AD_Org_ID); + if (dr != null && AD_Org_ID != 0) + dr.setAD_Org_ID(AD_Org_ID); // MAccount acct = null; if (getC_Charge_ID() != 0) @@ -132,11 +134,11 @@ public class Doc_Payment extends Doc acct = getAccount(Doc.ACCTTYPE_C_Prepayment, as); else acct = getAccount(Doc.ACCTTYPE_UnallocatedCash, as); - fl = fact.createLine(null, acct, + cr = fact.createLine(null, acct, getC_Currency_ID(), null, getAmount()); - if (fl != null && AD_Org_ID != 0 + if (cr != null && AD_Org_ID != 0 && getC_Charge_ID() == 0) // don't overwrite charge - fl.setAD_Org_ID(AD_Org_ID); + cr.setAD_Org_ID(AD_Org_ID); } // APP else if (getDocumentType().equals(DOCTYPE_APPayment)) @@ -148,17 +150,17 @@ public class Doc_Payment extends Doc acct = getAccount(Doc.ACCTTYPE_V_Prepayment, as); else acct = getAccount(Doc.ACCTTYPE_PaymentSelect, as); - FactLine fl = fact.createLine(null, acct, + dr = fact.createLine(null, acct, getC_Currency_ID(), getAmount(), null); - if (fl != null && AD_Org_ID != 0 + if (dr != null && AD_Org_ID != 0 && getC_Charge_ID() == 0) // don't overwrite charge - fl.setAD_Org_ID(AD_Org_ID); + dr.setAD_Org_ID(AD_Org_ID); // Asset - fl = fact.createLine(null, getAccount(Doc.ACCTTYPE_BankInTransit, as), + cr = fact.createLine(null, getAccount(Doc.ACCTTYPE_BankInTransit, as), getC_Currency_ID(), null, getAmount()); - if (fl != null && AD_Org_ID != 0) - fl.setAD_Org_ID(AD_Org_ID); + if (cr != null && AD_Org_ID != 0) + cr.setAD_Org_ID(AD_Org_ID); } else { @@ -166,6 +168,25 @@ public class Doc_Payment extends Doc log.log(Level.SEVERE, p_Error); fact = null; } + + // Avoid usage of clearing accounts + // If both accounts and orgs are the same then remove the posting + MAccount acct_dr = dr.getAccount(); + MAccount acct_cr = cr.getAccount(); + int org_dr = dr.getAD_Org_ID(); + int org_cr = cr.getAD_Org_ID(); + if (!as.isPostIfClearingEqual() && acct_dr!=null && acct_dr.equals(acct_cr) && org_dr == org_cr) { + + BigDecimal debit = dr.getAmtSourceDr(); + BigDecimal credit = cr.getAmtSourceCr(); + + if (debit.compareTo(credit) == 0) { + fact.remove(dr); + fact.remove(cr); + } + + } + // End Avoid usage of clearing accounts // ArrayList facts = new ArrayList(); facts.add(fact);