Related to issue 33650:Make use of persist org info column
authorAtul Gaware <atul.gaware@openbravo.com>
Fri, 27 Apr 2018 07:58:20 +0530
changeset 33890 a527992e0215
parent 33889 7c2d30c7653f
child 33891 a96849b0f373
Related to issue 33650:Make use of persist org info column

Use ad_inheritedcalendar_id
src-db/database/model/functions/C_GET_DEFAULT_PERIOD.xml
src-db/database/model/functions/C_INVOICE_POST.xml
src-db/database/model/functions/C_TAXPAYMENT_POST.xml
src-db/database/model/triggers/C_PERIOD_TRG.xml
src-db/database/sourcedata/AD_VAL_RULE.xml
src/org/openbravo/erpCommon/ad_reports/ReportTrialBalanceDetail_data.xsql
--- a/src-db/database/model/functions/C_GET_DEFAULT_PERIOD.xml	Thu Apr 26 22:17:42 2018 +0530
+++ b/src-db/database/model/functions/C_GET_DEFAULT_PERIOD.xml	Fri Apr 27 07:58:20 2018 +0530
@@ -19,14 +19,15 @@
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2012 Openbravo SLU
+* All portions are Copyright (C) 2012-2018 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
 
 /*
-* It returns the organization that owns the calendar for the p_organization Organization.
-* If no calendar is found, it returns NULL.
+* It returns the period from the inherited calendar of the invoice organization
+* based on p_defaultperiod input parameter.
+* If no period is found, it returns NULL.
 */
 
   v_calendar_id AD_Org.C_Calendar_ID%TYPE; 
@@ -36,10 +37,10 @@
   
 begin
 
-		SELECT C_CALENDAR_ID 
+		SELECT ad_inheritedcalendar_id
 		INTO v_calendar_id
 		FROM AD_ORG
-		WHERE AD_ORG_ID = AD_ORG_GETCALENDAROWNER((SELECT AD_ORG_ID FROM C_INVOICE WHERE C_INVOICE_ID = p_invoice));
+		WHERE AD_ORG_ID = (SELECT AD_ORG_ID FROM C_INVOICE WHERE C_INVOICE_ID = p_invoice);
 
 		SELECT DATEACCT 
 		INTO v_dateAcct
--- a/src-db/database/model/functions/C_INVOICE_POST.xml	Thu Apr 26 22:17:42 2018 +0530
+++ b/src-db/database/model/functions/C_INVOICE_POST.xml	Fri Apr 27 07:58:20 2018 +0530
@@ -173,7 +173,6 @@
   v_prepaymentamt NUMBER;
   v_hasTaxes NUMBER;
   v_calendarId C_CALENDAR.C_CALENDAR_ID%TYPE;
-  v_calendar_owner_id AD_Org.AD_Org_ID%TYPE;
    
 BEGIN
   IF (p_PInstance_ID IS NOT NULL) THEN
@@ -342,9 +341,8 @@
     /*
      * Avoids repeating the same documentno for the same organization tree within the same fiscal year
      */
-    SELECT AD_ORG_GETCALENDAROWNER(v_Org_ID) INTO v_calendar_owner_id FROM DUAL;
-    IF (v_calendar_owner_id IS NOT NULL) THEN
-      SELECT C_CALENDAR_ID INTO v_calendarId FROM AD_ORG WHERE AD_ORG_ID = v_calendar_owner_id;
+    SELECT ad_inheritedcalendar_id INTO v_calendarId FROM AD_ORG WHERE AD_ORG_ID = v_Org_ID;
+    IF (v_calendarId IS NOT NULL) THEN
       SELECT COUNT(*) INTO v_count
       FROM (SELECT Y.C_CALENDAR_ID, Y.C_YEAR_ID,
               MIN(P.STARTDATE) AS PERIODSTARTDATE, MAX(P.ENDDATE) AS PERIODENDDATE
--- a/src-db/database/model/functions/C_TAXPAYMENT_POST.xml	Thu Apr 26 22:17:42 2018 +0530
+++ b/src-db/database/model/functions/C_TAXPAYMENT_POST.xml	Fri Apr 27 07:58:20 2018 +0530
@@ -145,9 +145,9 @@
         v_paymentrule := 'T';
         v_currencyratetype := 'S';
 
-      select c_calendar_id into v_calendar_ID
+      select ad_inheritedcalendar_id into v_calendar_ID
       from ad_org
-      where ad_org_id = ad_org_getcalendarowner(v_org_id);
+      where ad_org_id = v_org_id;
 
       select c_period_id into v_period_id
       from c_period
--- a/src-db/database/model/triggers/C_PERIOD_TRG.xml	Thu Apr 26 22:17:42 2018 +0530
+++ b/src-db/database/model/triggers/C_PERIOD_TRG.xml	Fri Apr 27 07:58:20 2018 +0530
@@ -17,7 +17,7 @@
     * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
     * All Rights Reserved.
     * Contributor(s): Openbravo SLU
-    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.U.
+    * Contributions are Copyright (C) 2001-2018 Openbravo, S.L.U.
     *
     * Specifically, this derivative work is based upon the following Compiere
     * file and version.
@@ -41,11 +41,10 @@
                            WHERE o.ISREADY='Y'
                            AND o.ISPERIODCONTROLALLOWED='Y'
                            and exists (SELECT 1
-                                                  FROM C_Year, c_calendar, ad_org
+                                                  FROM C_Year, c_calendar
                                                   WHERE C_Year.c_calendar_id = c_calendar.c_calendar_id
-                                                  and c_calendar.c_calendar_id = ad_org.c_calendar_id
-                                                  and C_Year.C_Year_ID=:new.C_Year_ID
-                                                  and ad_org.ad_org_id = ad_org_getcalendarowner(o.AD_ORG_ID))
+                                                  and c_calendar.c_calendar_id = o.ad_inheritedcalendar_id
+                                                  and C_Year.C_Year_ID=:new.C_Year_ID)
                           ) a
        WHERE AD_Reference_ID='183'
        AND VALUE = (CASE WHEN :new.PeriodType = 'S' THEN VALUE ELSE 'GLJ' END)
--- a/src-db/database/sourcedata/AD_VAL_RULE.xml	Thu Apr 26 22:17:42 2018 +0530
+++ b/src-db/database/sourcedata/AD_VAL_RULE.xml	Fri Apr 27 07:58:20 2018 +0530
@@ -2228,7 +2228,7 @@
 <!--C9A72C5855CB4E29AFEB5DC17A5A9177-->  <NAME><![CDATA[C_Calendar and C_Year of an organization]]></NAME>
 <!--C9A72C5855CB4E29AFEB5DC17A5A9177-->  <DESCRIPTION><![CDATA[It ensures the calendar combobox shows always the calendar of the selected organization]]></DESCRIPTION>
 <!--C9A72C5855CB4E29AFEB5DC17A5A9177-->  <TYPE><![CDATA[S]]></TYPE>
-<!--C9A72C5855CB4E29AFEB5DC17A5A9177-->  <CODE><![CDATA[C_YEAR.C_CALENDAR_ID IN (SELECT DISTINCT(C_CALENDAR_ID) FROM AD_ORG WHERE AD_ORG_ID=AD_ORG_GETCALENDAROWNER(@AD_ORG_ID@))]]></CODE>
+<!--C9A72C5855CB4E29AFEB5DC17A5A9177-->  <CODE><![CDATA[C_YEAR.C_CALENDAR_ID IN (SELECT AD_InheritedCalendar_ID FROM AD_ORG WHERE AD_Client_ID= @AD_Client_ID@ AND AD_ORG_ID= @AD_Org_ID@)]]></CODE>
 <!--C9A72C5855CB4E29AFEB5DC17A5A9177-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--C9A72C5855CB4E29AFEB5DC17A5A9177--></AD_VAL_RULE>
 
@@ -2403,7 +2403,7 @@
 <!--E0541EB2493547BC934F5EFA044AB668-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--E0541EB2493547BC934F5EFA044AB668-->  <NAME><![CDATA[C_Period - Org Calendar Period]]></NAME>
 <!--E0541EB2493547BC934F5EFA044AB668-->  <TYPE><![CDATA[S]]></TYPE>
-<!--E0541EB2493547BC934F5EFA044AB668-->  <CODE><![CDATA[ exists (select 1 from c_year where c_period.c_year_id = c_year.c_year_id and (select c_calendar_id from ad_org where ad_org_id = ad_org_getcalendarowner (@AD_Org_ID@)) = c_year.c_calendar_id) and periodtype = 'S']]></CODE>
+<!--E0541EB2493547BC934F5EFA044AB668-->  <CODE><![CDATA[exists (select 1 from c_year where c_period.c_year_id = c_year.c_year_id and (SELECT AD_InheritedCalendar_ID FROM AD_ORG WHERE AD_Client_ID= @AD_Client_ID@ AND AD_ORG_ID= @AD_Org_ID@) = c_year.c_calendar_id) and periodtype = 'S']]></CODE>
 <!--E0541EB2493547BC934F5EFA044AB668-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--E0541EB2493547BC934F5EFA044AB668--></AD_VAL_RULE>
 
--- a/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalanceDetail_data.xsql	Thu Apr 26 22:17:42 2018 +0530
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalanceDetail_data.xsql	Fri Apr 27 07:58:20 2018 +0530
@@ -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-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -35,9 +35,9 @@
          LEFT JOIN C_PROJECT ON f.C_PROJECT_ID = C_PROJECT.C_PROJECT_ID
     WHERE F.ACCOUNT_ID = EV.C_ELEMENTVALUE_ID
          AND CAL.C_CALENDAR_ID = 
-            (SELECT C_CALENDAR_ID
+            (SELECT AD_INHERITEDCALENDAR_ID
              FROM AD_ORG
-             WHERE AD_ORG_ID = AD_ORG_GETCALENDAROWNER(?))
+             WHERE AD_ORG_ID = ?)
          AND f.AD_ORG_ID IN('2')
          AND F.AD_CLIENT_ID IN ('1')
          AND F.AD_ORG_ID IN('1')