Fixes bug 31265:AcctServer background should only consider valid GeneralLedgers
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Wed, 25 Nov 2015 14:35:30 +0100
changeset 28357 5fd88ad2aa0f
parent 28356 e3c7ca8c584f
child 28358 39adcac68310
Fixes bug 31265:AcctServer background should only consider valid GeneralLedgers

When Acct Server Process is executed from a process request for a organization different than *, tables to be posted will only be taken from General Ledgers which apply to organization being considered by Acct Server background process.
To be considered, these tables should also be as disable for background = 'N' in every general ledger that apply to organization being considered by Acct Server background process.
src/org/openbravo/erpCommon/ad_process/AcctServerProcess.java
src/org/openbravo/erpCommon/ad_process/AcctServerProcess_data.xsql
--- a/src/org/openbravo/erpCommon/ad_process/AcctServerProcess.java	Thu Nov 26 15:50:49 2015 +0000
+++ b/src/org/openbravo/erpCommon/ad_process/AcctServerProcess.java	Wed Nov 25 14:35:30 2015 +0100
@@ -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) 2009-2014 Openbravo SLU
+ * All portions are Copyright (C) 2009-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -115,10 +115,14 @@
     }
     try {
       final AcctServerProcessData[] data;
-      if ("0".equals(ctx.getClient()))
+      if ("0".equals(ctx.getClient())) {
         data = AcctServerProcessData.selectAcctTable(connection);
-      else
+      } else if ("0".equals(ctx.getOrganization())) {
         data = AcctServerProcessData.selectAcctTable(connection, ctx.getClient());
+      } else {
+        data = AcctServerProcessData.selectAcctTable(connection, ctx.getClient(),
+            ctx.getOrganization());
+      }
       final ArrayList<Object> vTableIds = new ArrayList<Object>();
       for (int i = 0; i < data.length; i++) {
         vTableIds.add(data[i].adTableId);
--- a/src/org/openbravo/erpCommon/ad_process/AcctServerProcess_data.xsql	Thu Nov 26 15:50:49 2015 +0000
+++ b/src/org/openbravo/erpCommon/ad_process/AcctServerProcess_data.xsql	Wed Nov 25 14:35:30 2015 +0100
@@ -12,7 +12,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) 2001-2014 Openbravo SLU
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -59,6 +59,31 @@
     ]]></Sql>
     <Parameter name="client"/>
    </SqlMethod>
+   <SqlMethod name="selectAcctTable" type="preparedStatement" return="multiple">
+      <SqlMethodComment></SqlMethodComment>
+      <Sql><![CDATA[
+      SELECT at.ad_table_id
+      FROM c_acctschema_table at
+      WHERE at.isactive = 'Y'
+      AND at.ad_client_id = ?
+      AND EXISTS (
+        SELECT 1
+        FROM c_acctschema a
+        JOIN ad_org_acctschema oa
+        ON a.c_acctschema_id = oa.c_acctschema_id
+        WHERE at.c_acctschema_id = a.c_acctschema_id
+        AND (ad_org_isinnaturaltree(?, oa.ad_org_id, oa.ad_client_id) = 'Y')
+        AND a.isactive = 'Y'
+        AND oa.isactive = 'Y'
+      )
+      GROUP BY at.ad_table_id
+      HAVING sum(case when at.isBackgroundDisabled = 'N' then 1 else 0 end) > 0
+      AND sum(case when at.isBackgroundDisabled = 'Y' then 1 else 0 end) = 0
+      ORDER BY at.ad_table_id
+    ]]></Sql>
+    <Parameter name="client"/>
+    <Parameter name="org"/>
+   </SqlMethod>
    <SqlMethod name="selectDescription" type="preparedStatement" return="string">
       <SqlMethodComment></SqlMethodComment>
       <Sql><![CDATA[