Fixes issue 30661: Payment Method not reloaded in Add Payment process
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Tue, 25 Aug 2015 14:00:35 +0200
changeset 27768 725f39b6fa93
parent 27767 d8a462db52bd
child 27769 ba4ab8980e96
Fixes issue 30661: Payment Method not reloaded in Add Payment process

Payment Method was not being reloaded when setting Business Partner in Add Payment process opened from Transaction tab.
ReceivedFromPaymentMethodActionHandler was not breaking the loop when a valid payment method was found.
Also, payment method name will be retrieved to display it correctly in Add Payment window.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ReceivedFromPaymentMethodActionHandler.java
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ReceivedFromPaymentMethodActionHandler.java	Tue Aug 25 14:29:25 2015 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ReceivedFromPaymentMethodActionHandler.java	Tue Aug 25 14:00:35 2015 +0200
@@ -21,6 +21,7 @@
 
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.client.kernel.BaseActionHandler;
@@ -41,6 +42,7 @@
           jsonData.getString("financialAccount"));
       boolean contains = false;
       String paymentMethod = null;
+      String paymentMethodName = null;
 
       if (financialAccount != null) {
         if (jsonData.has("receivedFrom") && jsonData.get("receivedFrom") != JSONObject.NULL) {
@@ -56,9 +58,9 @@
           }
           for (FinAccPaymentMethod finAccPaymentMethod : financialAccount
               .getFinancialMgmtFinAccPaymentMethodList()) {
-            if (finAccPaymentMethod.getPaymentMethod().equals(
-                OBDal.getInstance().get(FIN_PaymentMethod.class, paymentMethod))) {
+            if (StringUtils.equals(finAccPaymentMethod.getPaymentMethod().getId(), paymentMethod)) {
               contains = true;
+              break;
             } else {
               contains = false;
             }
@@ -67,10 +69,17 @@
       } else {
         contains = false;
       }
+
       if (!contains) {
         paymentMethod = "";
+        paymentMethodName = "";
+      } else {
+        paymentMethodName = OBDal.getInstance().get(FIN_PaymentMethod.class, paymentMethod)
+            .getName();
       }
+
       result.put("paymentMethodId", paymentMethod);
+      result.put("paymentMethodName", paymentMethodName);
       return result;
     } catch (Exception e) {
       throw new OBException(e);
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Tue Aug 25 14:29:25 2015 +0530
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Tue Aug 25 14:00:35 2015 +0200
@@ -985,13 +985,17 @@
       isSOTrx = form.getItem('issotrx').getValue(),
       financialAccount = form.getItem('fin_financial_account_id').getValue(),
       ordinvgrid = form.getItem('order_invoice').canvas.viewGrid,
+      paymentMethodItem = form.getItem('fin_paymentmethod_id'),
       newCriteria = {};
   affectedParams.push(form.getField('credit_to_use_display_logic').paramId);
   OB.APRM.AddPayment.recalcDisplayLogicOrReadOnlyLogic(form, view, affectedParams);
 
   callback = function (response, data, request) {
     if (data.paymentMethodId !== '') {
-      form.getItem('fin_paymentmethod_id').setValue(data.paymentMethodId);
+      paymentMethodItem.setValue(data.paymentMethodId);
+      paymentMethodItem.valueMap[data.paymentMethodId] = data.paymentMethodName;
+      form.redraw();
+      OB.APRM.AddPayment.paymentMethodOnChange(paymentMethodItem, view, form, grid);
     }
   };