details: https://code.openbravo.com/erp/devel/pi/rev/5f4c2906f294 changeset: 27530:5f4c2906f294 user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Fri Sep 04 10:26:47 2015 +0200 summary: Related to issue 30641: Reload payment method only if it is active
Reload payment method when changing business partner in the selector only if business partner default payment method is active for the current financial account. Also ReceivedFromPaymentMethodActionHandler performance has been improved. details: https://code.openbravo.com/erp/devel/pi/rev/1d78ee2328c6 changeset: 27531:1d78ee2328c6 user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Wed Sep 02 19:55:07 2015 +0200 summary: Fixes issue 30712: Payment Method not filled in Add Payment Payment Method was not filled when running Add Payment and business partner has no default Financial Account. When calling from getDefaultPaymentMethod to getFinancialAccountPaymentMethod in AddPaymentDefaultValuesHandler class with a null financialAccountId (in case of opening Add Payment from windows without Financial Account information like Purchase/Sales Order/Invoice and Business Partner does not have a default Financial Account setted), a NPE was raised and Payment Method was not filled in Add Payment. Now, in Purchase/Sales Order/Invoice windows, where is no financial account information in the context, document payment method will be taken if it is active for any financial account, if not, business partner default payment method will be taken instead (if it is active for any financial account and document organization has access to it). In those windows, Financial Account selector will show Business Partner default account if selected Payment Method belongs to it, or any Financial Account which Payment Method belongs to instead. In case of opening Add Payment from Payment In/Out windows, where exists Financial Account information in the context, Payment Method and Financial Account will be taken from the document. details: https://code.openbravo.com/erp/devel/pi/rev/ddf0351fd69a changeset: 27532:ddf0351fd69a user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Tue Sep 01 15:08:49 2015 +0200 summary: Fixes issue 30719: Deposit To in Add Payment does not filter correctly Deposit To in Add Payment should only show financial accounts where selected payment method is active. diffstat: modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUISEL_SELECTOR.xml | 2 +- modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ReceivedFromPaymentMethodActionHandler.java | 49 ++-- modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java | 112 +++++++-- 3 files changed, 103 insertions(+), 60 deletions(-) diffs (246 lines): diff -r 0a2625ff68a7 -r ddf0351fd69a modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUISEL_SELECTOR.xml --- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUISEL_SELECTOR.xml Thu Sep 03 15:00:55 2015 +0530 +++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUISEL_SELECTOR.xml Tue Sep 01 15:08:49 2015 +0200 @@ -55,7 +55,7 @@ <!--5D29D4DFCF4440B8BF89420419A0DBFE--> <NAME><![CDATA[Financial Account]]></NAME> <!--5D29D4DFCF4440B8BF89420419A0DBFE--> <AD_REFERENCE_ID><![CDATA[7F1A079A842545DF966D7EFD4BC5CFCE]]></AD_REFERENCE_ID> <!--5D29D4DFCF4440B8BF89420419A0DBFE--> <AD_TABLE_ID><![CDATA[B129E53BC0E747879F7BA17F0AECEC32]]></AD_TABLE_ID> -<!--5D29D4DFCF4440B8BF89420419A0DBFE--> <WHERECLAUSE><![CDATA[@fin_paymentmethod_id@ is null or exists (select 1 from FinancialMgmtFinAccPaymentMethod fpm join fpm.account as fa where fpm.paymentMethod.id = @fin_paymentmethod_id@ and fa = e and (case when @issotrx@ = 'true' then fpm.payinAllow else fpm.payoutAllow end) = true and (@c_currency_id@ = fa.currency.id or (case when @issotrx@ = 'true' then fpm.payinIsMulticurrency else fpm.payoutIsMulticurrency end) = true))]]></WHERECLAUSE> +<!--5D29D4DFCF4440B8BF89420419A0DBFE--> <WHERECLAUSE><![CDATA[@fin_paymentmethod_id@ is null or exists (select 1 from FinancialMgmtFinAccPaymentMethod fpm join fpm.account as fa where fpm.paymentMethod.id = @fin_paymentmethod_id@ and fa = e and (case when @issotrx@ = 'true' then fpm.payinAllow else fpm.payoutAllow end) = true and (@c_currency_id@ = fa.currency.id or (case when @issotrx@ = 'true' then fpm.payinIsMulticurrency else fpm.payoutIsMulticurrency end) = true) and fpm.active = true)]]></WHERECLAUSE> <!--5D29D4DFCF4440B8BF89420419A0DBFE--> <OBCLKER_TEMPLATE_ID><![CDATA[9314DE8599AD44E7BFC4CC50699042AB]]></OBCLKER_TEMPLATE_ID> <!--5D29D4DFCF4440B8BF89420419A0DBFE--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> <!--5D29D4DFCF4440B8BF89420419A0DBFE--> <SUGGESTIONTEXTMATCHSTYLE><![CDATA[startsWith]]></SUGGESTIONTEXTMATCHSTYLE> diff -r 0a2625ff68a7 -r ddf0351fd69a modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ReceivedFromPaymentMethodActionHandler.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ReceivedFromPaymentMethodActionHandler.java Thu Sep 03 15:00:55 2015 +0530 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ReceivedFromPaymentMethodActionHandler.java Tue Sep 01 15:08:49 2015 +0200 @@ -21,10 +21,11 @@ import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.codehaus.jettison.json.JSONObject; +import org.hibernate.criterion.Restrictions; import org.openbravo.base.exception.OBException; import org.openbravo.client.kernel.BaseActionHandler; +import org.openbravo.dal.service.OBCriteria; import org.openbravo.dal.service.OBDal; import org.openbravo.model.common.businesspartner.BusinessPartner; import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount; @@ -40,9 +41,9 @@ JSONObject result = new JSONObject(); FIN_FinancialAccount financialAccount = OBDal.getInstance().get(FIN_FinancialAccount.class, jsonData.getString("financialAccount")); - boolean contains = false; - String paymentMethod = null; - String paymentMethodName = null; + FIN_PaymentMethod paymentMethod = null; + String paymentMethodId = ""; + String paymentMethodName = ""; if (financialAccount != null) { if (jsonData.has("receivedFrom") && jsonData.get("receivedFrom") != JSONObject.NULL) { @@ -50,35 +51,31 @@ BusinessPartner businessPartner = OBDal.getInstance().get(BusinessPartner.class, receivedFrom); if (jsonData.getString("isSOTrx").toString().equals("true")) { - paymentMethod = businessPartner.getPaymentMethod() != null ? businessPartner - .getPaymentMethod().getId() : ""; + paymentMethod = businessPartner.getPaymentMethod(); } else { - paymentMethod = businessPartner.getPOPaymentMethod() != null ? businessPartner - .getPOPaymentMethod().getId() : ""; + paymentMethod = businessPartner.getPOPaymentMethod(); } - for (FinAccPaymentMethod finAccPaymentMethod : financialAccount - .getFinancialMgmtFinAccPaymentMethodList()) { - if (StringUtils.equals(finAccPaymentMethod.getPaymentMethod().getId(), paymentMethod)) { - contains = true; - break; - } else { - contains = false; + + if (paymentMethod != null) { + OBCriteria<FinAccPaymentMethod> criteria = OBDal.getInstance().createCriteria( + FinAccPaymentMethod.class); + criteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, financialAccount)); + criteria + .add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, paymentMethod)); + criteria.setFilterOnReadableOrganization(false); + criteria.setFilterOnActive(true); + criteria.setMaxResults(1); + FinAccPaymentMethod finAccPaymentMethod = (FinAccPaymentMethod) criteria.uniqueResult(); + + if (finAccPaymentMethod != null) { + paymentMethodId = finAccPaymentMethod.getPaymentMethod().getId(); + paymentMethodName = finAccPaymentMethod.getPaymentMethod().getName(); } } } - } else { - contains = false; } - if (!contains) { - paymentMethod = ""; - paymentMethodName = ""; - } else { - paymentMethodName = OBDal.getInstance().get(FIN_PaymentMethod.class, paymentMethod) - .getName(); - } - - result.put("paymentMethodId", paymentMethod); + result.put("paymentMethodId", paymentMethodId); result.put("paymentMethodName", paymentMethodName); return result; } catch (Exception e) { diff -r 0a2625ff68a7 -r ddf0351fd69a modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java Thu Sep 03 15:00:55 2015 +0530 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java Tue Sep 01 15:08:49 2015 +0200 @@ -282,32 +282,64 @@ && StringUtils.isNotEmpty(context.getString("Fin_Financial_Account_ID"))) { return context.getString("Fin_Financial_Account_ID"); } - String strBPartnerId = getDefaultReceivedFrom(requestMap); - if (StringUtils.isNotEmpty(strBPartnerId)) { - BusinessPartner businessPartner = OBDal.getInstance().get(BusinessPartner.class, - strBPartnerId); - boolean isSOTrx = "Y".equals(getDefaultIsSOTrx(requestMap)); - if (context.has("inpadClientId") && context.has("inpadOrgId")) { - final OrganizationStructureProvider osp = OBContext.getOBContext() - .getOrganizationStructureProvider(context.getString("inpadClientId")); - if (isSOTrx && businessPartner.getAccount() != null) { - if (osp.isInNaturalTree(businessPartner.getAccount().getOrganization(), OBDal - .getInstance().get(Organization.class, context.getString("inpadOrgId")))) { - return businessPartner.getAccount().getId(); - } else { - return ""; - } + String paymentMethodId = getDefaultPaymentMethod(requestMap); + if (StringUtils.isNotEmpty(paymentMethodId) && context.has("inpadClientId") + && context.has("inpadOrgId")) { - } else if (!isSOTrx && businessPartner.getPOFinancialAccount() != null) { - if (osp.isInNaturalTree(businessPartner.getPOFinancialAccount().getOrganization(), OBDal - .getInstance().get(Organization.class, context.getString("inpadOrgId")))) { - return businessPartner.getPOFinancialAccount().getId(); - } else { - return ""; - } + final OrganizationStructureProvider osp = OBContext.getOBContext() + .getOrganizationStructureProvider(context.getString("inpadClientId")); + String strBPartnerId = getDefaultReceivedFrom(requestMap); + if (StringUtils.isNotEmpty(strBPartnerId)) { + + BusinessPartner businessPartner = OBDal.getInstance().get(BusinessPartner.class, + strBPartnerId); + boolean isSOTrx = "Y".equals(getDefaultIsSOTrx(requestMap)); + + if (isSOTrx + && businessPartner.getAccount() != null + && getFinancialAccountPaymentMethod(paymentMethodId, businessPartner.getAccount() + .getId()) != null + && osp.isInNaturalTree(businessPartner.getAccount().getOrganization(), OBDal + .getInstance().get(Organization.class, context.getString("inpadOrgId")))) { + return businessPartner.getAccount().getId(); + } + + else if (!isSOTrx + && businessPartner.getPOFinancialAccount() != null + && getFinancialAccountPaymentMethod(paymentMethodId, businessPartner + .getPOFinancialAccount().getId()) != null + && osp.isInNaturalTree(businessPartner.getPOFinancialAccount().getOrganization(), OBDal + .getInstance().get(Organization.class, context.getString("inpadOrgId")))) { + return businessPartner.getPOFinancialAccount().getId(); } } + + FinAccPaymentMethod fpm = getFinancialAccountPaymentMethod(paymentMethodId, null); + if (fpm != null + && osp.isInNaturalTree(fpm.getAccount().getOrganization(), + OBDal.getInstance().get(Organization.class, context.getString("inpadOrgId")))) { + return fpm.getAccount().getId(); + } + } + + return null; + } + + private String getContextFinancialAccount(Map<String, String> requestMap) throws JSONException { + String strContext = requestMap.get("context"); + if (strContext == null) { + return null; + } + JSONObject context = new JSONObject(strContext); + if (context.has("inpfinFinancialAccountId") + && context.get("inpfinFinancialAccountId") != JSONObject.NULL + && StringUtils.isNotEmpty(context.getString("inpfinFinancialAccountId"))) { + return context.getString("inpfinFinancialAccountId"); + } else if (context.has("Fin_Financial_Account_ID") + && context.get("Fin_Financial_Account_ID") != JSONObject.NULL + && StringUtils.isNotEmpty(context.getString("Fin_Financial_Account_ID"))) { + return context.getString("Fin_Financial_Account_ID"); } return null; } @@ -331,26 +363,38 @@ && StringUtils.isNotEmpty(context.getString("inpfinPaymentmethodId"))) { strFinPaymentMethodId = context.getString("inpfinPaymentmethodId"); } - strFinancialAccountId = getDefaultFinancialAccount(requestMap); - if (strFinPaymentMethodId != null && strFinancialAccountId != null) { - if (getFinancialAccountPaymentMethod(strFinPaymentMethodId, strFinancialAccountId) != null) { - return strFinPaymentMethodId; - } + + strFinancialAccountId = getContextFinancialAccount(requestMap); + if (strFinPaymentMethodId != null + && getFinancialAccountPaymentMethod(strFinPaymentMethodId, strFinancialAccountId) != null) { + return strFinPaymentMethodId; } + String strBPartnerId = getDefaultReceivedFrom(requestMap); - if (StringUtils.isNotEmpty(strBPartnerId)) { + if (StringUtils.isNotEmpty(strBPartnerId) && context.has("inpadClientId") + && context.has("inpadOrgId")) { + + final OrganizationStructureProvider osp = OBContext.getOBContext() + .getOrganizationStructureProvider(context.getString("inpadClientId")); BusinessPartner businessPartner = OBDal.getInstance().get(BusinessPartner.class, strBPartnerId); boolean isSOTrx = "Y".equals(getDefaultIsSOTrx(requestMap)); + if (isSOTrx && businessPartner.getPaymentMethod() != null && getFinancialAccountPaymentMethod(businessPartner.getPaymentMethod().getId(), - strFinancialAccountId) != null) { + strFinancialAccountId) != null + && osp.isInNaturalTree(businessPartner.getPaymentMethod().getOrganization(), OBDal + .getInstance().get(Organization.class, context.getString("inpadOrgId")))) { return businessPartner.getPaymentMethod().getId(); - } else if (!isSOTrx + } + + else if (!isSOTrx && businessPartner.getPOPaymentMethod() != null && getFinancialAccountPaymentMethod(businessPartner.getPOPaymentMethod().getId(), - strFinancialAccountId) != null) { + strFinancialAccountId) != null + && osp.isInNaturalTree(businessPartner.getPOPaymentMethod().getOrganization(), OBDal + .getInstance().get(Organization.class, context.getString("inpadOrgId")))) { return businessPartner.getPOPaymentMethod().getId(); } } @@ -428,8 +472,10 @@ FinAccPaymentMethod.class); obc.setFilterOnReadableOrganization(false); obc.setMaxResults(1); - obc.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, - OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId))); + if (!StringUtils.isEmpty(financialAccountId)) { + obc.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, + OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId))); + } obc.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, OBDal.getInstance().get(FIN_PaymentMethod.class, paymentMethodId))); return (FinAccPaymentMethod) obc.uniqueResult(); ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits