[ 1885417 ] Validate BP on Payment Prepare or BeforeSave

This commit is contained in:
Carlos Ruiz 2008-02-03 00:25:18 +00:00
parent 91a394aaaf
commit b2865c6d2f
2 changed files with 43 additions and 20 deletions

View File

@ -595,6 +595,25 @@ public final class MPayment extends X_C_Payment
setAD_Org_ID(ba.getAD_Org_ID()); 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; return true;
} // beforeSave } // beforeSave

View File

@ -1132,10 +1132,11 @@ public class VPayment extends CDialog
} }
m_mPayment.setDateTrx(m_DateAcct); m_mPayment.setDateTrx(m_DateAcct);
m_mPayment.setDateAcct(m_DateAcct); m_mPayment.setDateAcct(m_DateAcct);
m_mPayment.save(); if (!m_mPayment.save())
ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated");;
// Save/Post // 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); boolean ok = m_mPayment.processIt(DocAction.ACTION_Complete);
m_mPayment.save(); m_mPayment.save();
@ -1390,26 +1391,29 @@ public class VPayment extends CDialog
m_mPayment.setDateTrx(m_DateAcct); m_mPayment.setDateTrx(m_DateAcct);
// Set Amount // Set Amount
m_mPayment.setAmount(m_C_Currency_ID, m_Amount); m_mPayment.setAmount(m_C_Currency_ID, m_Amount);
if (!m_mPayment.save()) {
approved = m_mPayment.processOnline(); ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated");
info = m_mPayment.getR_RespMsg() + " (" + m_mPayment.getR_AuthCode() } else {
+ ") ID=" + m_mPayment.getR_PnRef(); approved = m_mPayment.processOnline();
boolean saved = m_mPayment.save(); info = m_mPayment.getR_RespMsg() + " (" + m_mPayment.getR_AuthCode()
+ ") ID=" + m_mPayment.getR_PnRef();
if (approved)
{
boolean ok = m_mPayment.processIt(DocAction.ACTION_Complete);
m_mPayment.save(); 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 else
ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated"); {
saveChanges(); ADialog.error(m_WindowNo, this, "PaymentNotProcessed", info);
dispose(); }
}
else
{
ADialog.error(m_WindowNo, this, "PaymentNotProcessed", info);
} }
} }
else else