Fixes Issue 25483: It is not possible to add a validate rule to fin_financial_account_id column of fin_payment table
authorPandeeswari Ramakrishnan <pandeeswari.ramakrishnan@openbravo.com>
Mon, 07 Apr 2014 00:47:11 +0530
changeset 22878 e3ae82ec9ee3
parent 22877 a7130dd050ca
child 22879 97d8cf3e7d76
Fixes Issue 25483: It is not possible to add a validate rule to fin_financial_account_id column of fin_payment table
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_VAL_RULE.xml
src/org/openbravo/erpCommon/ad_callouts/SE_PaymentMethod_FinAccount.java
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Sun Apr 06 18:24:19 2014 +0530
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Mon Apr 07 00:47:11 2014 +0530
@@ -220565,7 +220565,8 @@
 <!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <COLUMNNAME><![CDATA[Fin_Financial_Account_ID]]></COLUMNNAME>
 <!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <AD_TABLE_ID><![CDATA[D1A97202E832470285C9B1EB026D54E2]]></AD_TABLE_ID>
 <!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <AD_REFERENCE_ID><![CDATA[19]]></AD_REFERENCE_ID>
-<!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <FIELDLENGTH><![CDATA[0]]></FIELDLENGTH>
+<!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <AD_VAL_RULE_ID><![CDATA[6910516E0A54432CA2E6A0C058346F92]]></AD_VAL_RULE_ID>
+<!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
 <!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <ISKEY><![CDATA[N]]></ISKEY>
 <!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <ISPARENT><![CDATA[N]]></ISPARENT>
 <!--03276FB53CC54CC1829E0AA6EC0F2EE6-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
@@ -279374,6 +279375,7 @@
 <!--828EE0AE802F5FA1E040007F010067C7-->  <AD_TABLE_ID><![CDATA[291]]></AD_TABLE_ID>
 <!--828EE0AE802F5FA1E040007F010067C7-->  <AD_REFERENCE_ID><![CDATA[18]]></AD_REFERENCE_ID>
 <!--828EE0AE802F5FA1E040007F010067C7-->  <AD_REFERENCE_VALUE_ID><![CDATA[DF1CEA94B3564A33AFDB37C07E1CE353]]></AD_REFERENCE_VALUE_ID>
+<!--828EE0AE802F5FA1E040007F010067C7-->  <AD_VAL_RULE_ID><![CDATA[3041353DA35A4C17BC434CF80FEE9CC9]]></AD_VAL_RULE_ID>
 <!--828EE0AE802F5FA1E040007F010067C7-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
 <!--828EE0AE802F5FA1E040007F010067C7-->  <ISKEY><![CDATA[N]]></ISKEY>
 <!--828EE0AE802F5FA1E040007F010067C7-->  <ISPARENT><![CDATA[N]]></ISPARENT>
@@ -279410,6 +279412,7 @@
 <!--828EE0AE80305FA1E040007F010067C7-->  <AD_TABLE_ID><![CDATA[291]]></AD_TABLE_ID>
 <!--828EE0AE80305FA1E040007F010067C7-->  <AD_REFERENCE_ID><![CDATA[18]]></AD_REFERENCE_ID>
 <!--828EE0AE80305FA1E040007F010067C7-->  <AD_REFERENCE_VALUE_ID><![CDATA[DF1CEA94B3564A33AFDB37C07E1CE353]]></AD_REFERENCE_VALUE_ID>
+<!--828EE0AE80305FA1E040007F010067C7-->  <AD_VAL_RULE_ID><![CDATA[F7DCC072355648E7BFFF05014361A44C]]></AD_VAL_RULE_ID>
 <!--828EE0AE80305FA1E040007F010067C7-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
 <!--828EE0AE80305FA1E040007F010067C7-->  <ISKEY><![CDATA[N]]></ISKEY>
 <!--828EE0AE80305FA1E040007F010067C7-->  <ISPARENT><![CDATA[N]]></ISPARENT>
--- a/src-db/database/sourcedata/AD_VAL_RULE.xml	Sun Apr 06 18:24:19 2014 +0530
+++ b/src-db/database/sourcedata/AD_VAL_RULE.xml	Mon Apr 07 00:47:11 2014 +0530
@@ -1353,6 +1353,17 @@
 <!--2E7335B7F14041DFBC61DCE771B1A57B-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--2E7335B7F14041DFBC61DCE771B1A57B--></AD_VAL_RULE>
 
+<!--3041353DA35A4C17BC434CF80FEE9CC9--><AD_VAL_RULE>
+<!--3041353DA35A4C17BC434CF80FEE9CC9-->  <AD_VAL_RULE_ID><![CDATA[3041353DA35A4C17BC434CF80FEE9CC9]]></AD_VAL_RULE_ID>
+<!--3041353DA35A4C17BC434CF80FEE9CC9-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3041353DA35A4C17BC434CF80FEE9CC9-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3041353DA35A4C17BC434CF80FEE9CC9-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3041353DA35A4C17BC434CF80FEE9CC9-->  <NAME><![CDATA[Financial Account - Customer]]></NAME>
+<!--3041353DA35A4C17BC434CF80FEE9CC9-->  <TYPE><![CDATA[S]]></TYPE>
+<!--3041353DA35A4C17BC434CF80FEE9CC9-->  <CODE><![CDATA[Fin_Financial_Account_ID IN (SELECT Fin_Financial_Account_ID FROM Fin_Finacc_Paymentmethod WHERE Fin_Paymentmethod_ID=@Fin_Paymentmethod_ID@)]]></CODE>
+<!--3041353DA35A4C17BC434CF80FEE9CC9-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3041353DA35A4C17BC434CF80FEE9CC9--></AD_VAL_RULE>
+
 <!--324A9767D9B94A8A8154DEB3ACA6E063--><AD_VAL_RULE>
 <!--324A9767D9B94A8A8154DEB3ACA6E063-->  <AD_VAL_RULE_ID><![CDATA[324A9767D9B94A8A8154DEB3ACA6E063]]></AD_VAL_RULE_ID>
 <!--324A9767D9B94A8A8154DEB3ACA6E063-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1610,6 +1621,17 @@
 <!--6770688C3FBC4D139DEE04BF67997D55-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--6770688C3FBC4D139DEE04BF67997D55--></AD_VAL_RULE>
 
+<!--6910516E0A54432CA2E6A0C058346F92--><AD_VAL_RULE>
+<!--6910516E0A54432CA2E6A0C058346F92-->  <AD_VAL_RULE_ID><![CDATA[6910516E0A54432CA2E6A0C058346F92]]></AD_VAL_RULE_ID>
+<!--6910516E0A54432CA2E6A0C058346F92-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--6910516E0A54432CA2E6A0C058346F92-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--6910516E0A54432CA2E6A0C058346F92-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--6910516E0A54432CA2E6A0C058346F92-->  <NAME><![CDATA[Fin_FinancialAccountofPaymentMethod]]></NAME>
+<!--6910516E0A54432CA2E6A0C058346F92-->  <TYPE><![CDATA[S]]></TYPE>
+<!--6910516E0A54432CA2E6A0C058346F92-->  <CODE><![CDATA[Fin_Financial_Account_ID IN (SELECT Fin_Financial_Account_ID FROM Fin_Finacc_Paymentmethod WHERE Fin_Paymentmethod_ID=@Fin_Paymentmethod_ID@ AND CASE WHEN @IsReceipt@='Y' THEN Payin_Allow='Y' ELSE Payout_Allow='Y' END)]]></CODE>
+<!--6910516E0A54432CA2E6A0C058346F92-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--6910516E0A54432CA2E6A0C058346F92--></AD_VAL_RULE>
+
 <!--6BAE0C5334EE468DB58E0806C4F54FF0--><AD_VAL_RULE>
 <!--6BAE0C5334EE468DB58E0806C4F54FF0-->  <AD_VAL_RULE_ID><![CDATA[6BAE0C5334EE468DB58E0806C4F54FF0]]></AD_VAL_RULE_ID>
 <!--6BAE0C5334EE468DB58E0806C4F54FF0-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -2201,6 +2223,17 @@
 <!--F5C1AEE7CA3D4EF690406695F212E463-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--F5C1AEE7CA3D4EF690406695F212E463--></AD_VAL_RULE>
 
+<!--F7DCC072355648E7BFFF05014361A44C--><AD_VAL_RULE>
+<!--F7DCC072355648E7BFFF05014361A44C-->  <AD_VAL_RULE_ID><![CDATA[F7DCC072355648E7BFFF05014361A44C]]></AD_VAL_RULE_ID>
+<!--F7DCC072355648E7BFFF05014361A44C-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F7DCC072355648E7BFFF05014361A44C-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F7DCC072355648E7BFFF05014361A44C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F7DCC072355648E7BFFF05014361A44C-->  <NAME><![CDATA[Financial Account - Vendor]]></NAME>
+<!--F7DCC072355648E7BFFF05014361A44C-->  <TYPE><![CDATA[S]]></TYPE>
+<!--F7DCC072355648E7BFFF05014361A44C-->  <CODE><![CDATA[Fin_Financial_Account_ID IN (SELECT Fin_Financial_Account_ID FROM Fin_Finacc_Paymentmethod WHERE Fin_Paymentmethod_ID=@PO_Paymentmethod_ID@)]]></CODE>
+<!--F7DCC072355648E7BFFF05014361A44C-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--F7DCC072355648E7BFFF05014361A44C--></AD_VAL_RULE>
+
 <!--F998285191EA4BA9AC839BF540016DB4--><AD_VAL_RULE>
 <!--F998285191EA4BA9AC839BF540016DB4-->  <AD_VAL_RULE_ID><![CDATA[F998285191EA4BA9AC839BF540016DB4]]></AD_VAL_RULE_ID>
 <!--F998285191EA4BA9AC839BF540016DB4-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_PaymentMethod_FinAccount.java	Sun Apr 06 18:24:19 2014 +0530
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_PaymentMethod_FinAccount.java	Mon Apr 07 00:47:11 2014 +0530
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2011 Openbravo SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -36,77 +36,47 @@
   @Override
   protected void execute(CalloutInfo info) throws ServletException {
 
-    String srtPaymentMethodId = info.getStringParameter("inpfinPaymentmethodId",
-        IsIDFilter.instance);
-    String srtPOPaymentMethodId = info.getStringParameter("inppoPaymentmethodId",
-        IsIDFilter.instance);
-
     String tabId = info.getTabId();
     boolean isVendorTab = "224".equals(tabId);
     String finIsReceipt = info.getStringParameter("inpisreceipt", null);
     boolean isPaymentOut = isVendorTab || "N".equals(finIsReceipt);
-    String srtOrgId = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+    String strOrgId = info.getStringParameter("inpadOrgId", IsIDFilter.instance);
+
+    String strSelectedPaymentMethod = info.getStringParameter(isVendorTab ? "inppoPaymentmethodId"
+        : "inpfinPaymentmethodId", IsIDFilter.instance);
 
     FIN_PaymentMethod paymentMethod = OBDal.getInstance().get(FIN_PaymentMethod.class,
-        isVendorTab ? srtPOPaymentMethodId : srtPaymentMethodId);
+        strSelectedPaymentMethod);
 
-    info.addSelect(isVendorTab ? "inppoFinancialAccountId" : "inpfinFinancialAccountId");
-    String srtSelectedFinancialAccount = info.getStringParameter(
+    String strSelectedFinancialAccount = info.getStringParameter(
         isVendorTab ? "inppoFinancialAccountId" : "inpfinFinancialAccountId", IsIDFilter.instance);
 
-    boolean isSelected = true;
+    FIN_FinancialAccount financialAccount = OBDal.getInstance().get(FIN_FinancialAccount.class,
+        strSelectedFinancialAccount);
+
     boolean isMultiCurrencyEnabled = false;
 
-    // No Payment Method selected
-    if (srtPaymentMethodId.isEmpty() && srtPOPaymentMethodId.isEmpty()) {
-      OBCriteria<FIN_FinancialAccount> obc = OBDal.getInstance().createCriteria(
-          FIN_FinancialAccount.class);
-      obc.add(Restrictions.in("organization.id", OBContext.getOBContext()
-          .getOrganizationStructureProvider().getNaturalTree(srtOrgId)));
-      obc.setFilterOnReadableOrganization(false);
-      for (FIN_FinancialAccount acc : obc.list()) {
-        info.addSelectResult(acc.getId(), acc.getIdentifier());
-      }
-
-    } else {
+    if (paymentMethod != null && financialAccount != null) {
       OBCriteria<FinAccPaymentMethod> obc = OBDal.getInstance().createCriteria(
           FinAccPaymentMethod.class);
+      // (paymentmethod, financial_account) is unique
       obc.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, paymentMethod));
+      obc.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, financialAccount));
       obc.add(Restrictions.in("organization.id", OBContext.getOBContext()
-          .getOrganizationStructureProvider().getNaturalTree(srtOrgId)));
-      if (isPaymentOut) {
-        obc.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYOUTALLOW, true));
-      } else {
-        obc.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYINALLOW, true));
-      }
+          .getOrganizationStructureProvider().getNaturalTree(strOrgId)));
 
-      FinAccPaymentMethod selectedPaymentMethod = null;
-      for (FinAccPaymentMethod accPm : obc.list()) {
-        if (accPm.getAccount().isActive()) {
-          if (srtSelectedFinancialAccount.equals(accPm.getAccount().getId())) {
-            isSelected = true;
-          } else if (srtSelectedFinancialAccount.isEmpty()) {
-            srtSelectedFinancialAccount = accPm.getAccount().getIdentifier();
-            isSelected = true;
-          }
-          selectedPaymentMethod = accPm;
+      if (obc.count() > 0) {
+        FinAccPaymentMethod selectedAccPaymentMethod = obc.list().get(0);
 
-          info.addSelectResult(accPm.getAccount().getId(), accPm.getAccount().getIdentifier(),
-              isSelected);
-        }
-        isSelected = false;
-      }
-      if (selectedPaymentMethod != null) {
         if (isPaymentOut) {
-          isMultiCurrencyEnabled = selectedPaymentMethod.isPayoutAllow()
-              && selectedPaymentMethod.isPayoutIsMulticurrency();
+          isMultiCurrencyEnabled = selectedAccPaymentMethod.isPayoutAllow()
+              && selectedAccPaymentMethod.isPayoutIsMulticurrency();
         } else {
-          isMultiCurrencyEnabled = selectedPaymentMethod.isPayinAllow()
-              && selectedPaymentMethod.isPayinIsMulticurrency();
+          isMultiCurrencyEnabled = selectedAccPaymentMethod.isPayinAllow()
+              && selectedAccPaymentMethod.isPayinIsMulticurrency();
         }
       }
     }
-    info.endSelect();
     info.addResult("inpismulticurrencyenabled", isMultiCurrencyEnabled ? "Y" : "N");
   }
 }