From 2457108af3d82dc99f3fa944904527c1b5759d88 Mon Sep 17 00:00:00 2001 From: phib Date: Wed, 3 Jun 2009 05:18:36 +0000 Subject: [PATCH] 2800319 Payment completion doesn't set BP open balance. https://sourceforge.net/tracker/?func=detail&aid=2800319&group_id=176962&atid=879332 --- base/src/org/compiere/model/MPayment.java | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/base/src/org/compiere/model/MPayment.java b/base/src/org/compiere/model/MPayment.java index 43e0c3e9d4..c220e8f6c4 100644 --- a/base/src/org/compiere/model/MPayment.java +++ b/base/src/org/compiere/model/MPayment.java @@ -1770,10 +1770,29 @@ public final class MPayment extends X_C_Payment // MProject project = new MProject(getCtx(), getC_Project_ID()); } // Update BP for Prepayments - if (getC_BPartner_ID() != 0 && getC_Invoice_ID() == 0) + if (getC_BPartner_ID() != 0 && getC_Invoice_ID() == 0 && getC_Charge_ID() == 0) { MBPartner bp = new MBPartner (getCtx(), getC_BPartner_ID(), get_TrxName()); - bp.setTotalOpenBalance(); + // Update total balance to include this payment + BigDecimal payAmt = MConversionRate.convertBase(getCtx(), getPayAmt(), + getC_Currency_ID(), getDateAcct(), getC_ConversionType_ID(), getAD_Client_ID(), getAD_Org_ID()); + if (payAmt == null) + { + m_processMsg = "Could not convert C_Currency_ID=" + getC_Currency_ID() + + " to base C_Currency_ID=" + MClient.get(Env.getCtx()).getC_Currency_ID(); + return DocAction.STATUS_Invalid; + } + // Total Balance + BigDecimal newBalance = bp.getTotalOpenBalance(false); + if (newBalance == null) + newBalance = Env.ZERO; + if (isReceipt()) + newBalance = newBalance.subtract(payAmt); + else + newBalance = newBalance.add(payAmt); + + bp.setTotalOpenBalance(newBalance); + bp.setSOCreditStatus(); bp.save(); }