Fixed bug 27119: Wrong default value in deposit to combo
authorSandra Huguet <sandra.huguet@openbravo.com>
Thu, 17 Jul 2014 18:38:00 +0200
changeset 24175 8c5e2f247bdf
parent 24174 f2e505b2c964
child 24176 ec3d60bf2df4
Fixed bug 27119: Wrong default value in deposit to combo
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java	Fri Jul 18 12:49:36 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/AddPaymentDefaultValuesHandler.java	Thu Jul 17 18:38:00 2014 +0200
@@ -29,6 +29,8 @@
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.security.OrganizationStructureProvider;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.common.businesspartner.BusinessPartner;
 import org.openbravo.model.common.enterprise.Organization;
@@ -134,10 +136,25 @@
       BusinessPartner businessPartner = OBDal.getInstance().get(BusinessPartner.class,
           strBPartnerId);
       boolean isSOTrx = "Y".equals(getDefaultIsSOTrx(requestMap));
-      if (isSOTrx && businessPartner.getAccount() != null) {
-        return businessPartner.getAccount().getId();
-      } else if (!isSOTrx && businessPartner.getPOFinancialAccount() != null) {
-        return businessPartner.getPOFinancialAccount().getId();
+      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 "";
+          }
+
+        } 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 "";
+          }
+        }
       }
     }
     return null;