details: https://code.openbravo.com/erp/devel/pi/rev/e7bf20e738da changeset: 28132:e7bf20e738da user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Tue Sep 29 12:00:47 2015 +0200 summary: Fixes issue 30954: NPE in SE_Payment_BPartner callout
A NPE was raised in SE_Payment_BPartner callout, when selecting a business partner in Payment In or Payment Out window with no default payment method or financial account. diffstat: src/org/openbravo/erpCommon/ad_callouts/SE_Payment_BPartner.java | 53 ++++++--- 1 files changed, 32 insertions(+), 21 deletions(-) diffs (65 lines): diff -r 8942b6596f0b -r e7bf20e738da src/org/openbravo/erpCommon/ad_callouts/SE_Payment_BPartner.java --- a/src/org/openbravo/erpCommon/ad_callouts/SE_Payment_BPartner.java Thu Dec 10 15:10:00 2015 +0530 +++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Payment_BPartner.java Tue Sep 29 12:00:47 2015 +0200 @@ -56,29 +56,40 @@ paymentMethod = bpartner.getPOPaymentMethod(); financialAccount = bpartner.getPOFinancialAccount(); } - final OBCriteria<FinAccPaymentMethod> apmCriteria = OBDal.getInstance().createCriteria(FinAccPaymentMethod.class); - apmCriteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, paymentMethod)); - apmCriteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, financialAccount)); - apmCriteria.setFilterOnActive(false); - FinAccPaymentMethod accPaymentMethod = (FinAccPaymentMethod) apmCriteria.uniqueResult(); - if (financialAccount.isActive() && accPaymentMethod.isActive()) { - try { - info.addResult("inpfinPaymentmethodId", isReceipt ? bpartner.getPaymentMethod().getId() - : bpartner.getPOPaymentMethod().getId()); - info.addResult("inpfinFinancialAccountId", isReceipt ? bpartner.getAccount().getId() - : bpartner.getPOFinancialAccount().getId()); - } catch (Exception e) { + + if (paymentMethod != null && financialAccount != null) { + final OBCriteria<FinAccPaymentMethod> apmCriteria = OBDal.getInstance().createCriteria( + FinAccPaymentMethod.class); + apmCriteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, paymentMethod)); + apmCriteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, financialAccount)); + apmCriteria.setFilterOnActive(false); + FinAccPaymentMethod accPaymentMethod = (FinAccPaymentMethod) apmCriteria.uniqueResult(); + if (accPaymentMethod != null) { + if (financialAccount.isActive() && accPaymentMethod.isActive()) { + info.addResult("inpfinPaymentmethodId", paymentMethod.getId()); + info.addResult("inpfinFinancialAccountId", financialAccount.getId()); + } else if (!financialAccount.isActive() && !accPaymentMethod.isActive()) { + info.addResult( + "WARNING", + String.format( + Utility.messageBD(new DalConnectionProvider(), "finnac_paymet_inact", + vars.getLanguage()), financialAccount.getIdentifier(), + paymentMethod.getIdentifier())); + } else if (!financialAccount.isActive()) { + info.addResult( + "WARNING", + String.format(Utility.messageBD(new DalConnectionProvider(), "finnac_inact", + vars.getLanguage()), financialAccount.getIdentifier())); + } else if (!accPaymentMethod.isActive()) { + info.addResult("WARNING", String.format( + Utility.messageBD(new DalConnectionProvider(), "paymet_inact", vars.getLanguage()), + paymentMethod.getIdentifier(), financialAccount.getIdentifier())); + } + } else { log4j.info("No default info for the selected business partner"); } - } else if (!financialAccount.isActive() && !accPaymentMethod.isActive()) { - info.addResult("WARNING", String.format( - Utility.messageBD(new DalConnectionProvider(), "finnac_paymet_inact", vars.getLanguage()), financialAccount.getIdentifier(), paymentMethod.getIdentifier())); - } else if (!financialAccount.isActive()) { - info.addResult("WARNING", String.format( - Utility.messageBD(new DalConnectionProvider(), "finnac_inact", vars.getLanguage()), financialAccount.getIdentifier())); - } else if (!accPaymentMethod.isActive()) { - info.addResult("WARNING", String.format( - Utility.messageBD(new DalConnectionProvider(), "paymet_inact", vars.getLanguage()), paymentMethod.getIdentifier(), financialAccount.getIdentifier())); + } else { + log4j.info("No default info for the selected business partner"); } if ((!strcBpartnerId.equals("")) && (FIN_Utility.isBlockedBusinessPartner(strcBpartnerId, "Y".equals(strisreceipt), 4))) { ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits