From b2865c6d2fbddf1c655670f91cdcd7cdbbbe8b59 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sun, 3 Feb 2008 00:25:18 +0000 Subject: [PATCH] [ 1885417 ] Validate BP on Payment Prepare or BeforeSave --- base/src/org/compiere/model/MPayment.java | 19 ++++++++++ client/src/org/compiere/grid/VPayment.java | 44 ++++++++++++---------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/base/src/org/compiere/model/MPayment.java b/base/src/org/compiere/model/MPayment.java index b193d2e312..d09cf93d21 100644 --- a/base/src/org/compiere/model/MPayment.java +++ b/base/src/org/compiere/model/MPayment.java @@ -595,6 +595,25 @@ public final class MPayment extends X_C_Payment setAD_Org_ID(ba.getAD_Org_ID()); } + // [ adempiere-Bugs-1885417 ] Validate BP on Payment Prepare or BeforeSave + // there is bp and (invoice or order) + if (getC_BPartner_ID() != 0 && (getC_Invoice_ID() != 0 || getC_Order_ID() != 0)) { + if (getC_Invoice_ID() != 0) { + MInvoice inv = new MInvoice(getCtx(), getC_Invoice_ID(), get_TrxName()); + if (inv.getC_BPartner_ID() != getC_BPartner_ID()) { + log.saveError("Error", Msg.parseTranslation(getCtx(), "BP different from BP Invoice")); + return false; + } + } + if (getC_Order_ID() != 0) { + MOrder ord = new MOrder(getCtx(), getC_Order_ID(), get_TrxName()); + if (ord.getC_BPartner_ID() != getC_BPartner_ID()) { + log.saveError("Error", Msg.parseTranslation(getCtx(), "BP different from BP Order")); + return false; + } + } + } + return true; } // beforeSave diff --git a/client/src/org/compiere/grid/VPayment.java b/client/src/org/compiere/grid/VPayment.java index d1169755c9..6a3dca9c69 100644 --- a/client/src/org/compiere/grid/VPayment.java +++ b/client/src/org/compiere/grid/VPayment.java @@ -1132,10 +1132,11 @@ public class VPayment extends CDialog } m_mPayment.setDateTrx(m_DateAcct); m_mPayment.setDateAcct(m_DateAcct); - m_mPayment.save(); + if (!m_mPayment.save()) + ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated");; // Save/Post - if (MPayment.DOCSTATUS_Drafted.equals(m_mPayment.getDocStatus())) + if (m_mPayment.get_ID() > 0 && MPayment.DOCSTATUS_Drafted.equals(m_mPayment.getDocStatus())) { boolean ok = m_mPayment.processIt(DocAction.ACTION_Complete); m_mPayment.save(); @@ -1390,26 +1391,29 @@ public class VPayment extends CDialog m_mPayment.setDateTrx(m_DateAcct); // Set Amount m_mPayment.setAmount(m_C_Currency_ID, m_Amount); - - approved = m_mPayment.processOnline(); - info = m_mPayment.getR_RespMsg() + " (" + m_mPayment.getR_AuthCode() - + ") ID=" + m_mPayment.getR_PnRef(); - boolean saved = m_mPayment.save(); - - if (approved) - { - boolean ok = m_mPayment.processIt(DocAction.ACTION_Complete); + if (!m_mPayment.save()) { + ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated"); + } else { + approved = m_mPayment.processOnline(); + info = m_mPayment.getR_RespMsg() + " (" + m_mPayment.getR_AuthCode() + + ") ID=" + m_mPayment.getR_PnRef(); m_mPayment.save(); - if (ok) - ADialog.info(m_WindowNo, this, "PaymentProcessed", info + "\n" + m_mPayment.getDocumentNo()); + + if (approved) + { + boolean ok = m_mPayment.processIt(DocAction.ACTION_Complete); + m_mPayment.save(); + if (ok) + ADialog.info(m_WindowNo, this, "PaymentProcessed", info + "\n" + m_mPayment.getDocumentNo()); + else + ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated"); + saveChanges(); + dispose(); + } else - ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated"); - saveChanges(); - dispose(); - } - else - { - ADialog.error(m_WindowNo, this, "PaymentNotProcessed", info); + { + ADialog.error(m_WindowNo, this, "PaymentNotProcessed", info); + } } } else