fixes issue 33572: Ability to define a Report Template as default
authorCarlos Aristu <carlos.aristu@openbravo.com>
Tue, 02 Aug 2016 10:49:13 +0200
changeset 30056 5dd3611e7164
parent 30055 7ebe0a53a425
child 30057 990a797ec886
fixes issue 33572: Ability to define a Report Template as default

A new field is added to the Report Template tab in the Document Type window. It is a checkbox that can be used to mark a template as default. If a template is marked as default, is the one that will be selected when printing the document. Also a new trigger has been created in order to allow just one default template per document type.
src-db/database/model/tables/C_POC_DOCTYPE_TEMPLATE.xml
src-db/database/model/triggers/C_POC_DOCTYPE_TEMPLATE_TRG.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_FIELD.xml
src/org/openbravo/erpCommon/utility/reporting/Template_data.xsql
--- a/src-db/database/model/tables/C_POC_DOCTYPE_TEMPLATE.xml	Mon Aug 01 13:21:44 2016 +0200
+++ b/src-db/database/model/tables/C_POC_DOCTYPE_TEMPLATE.xml	Tue Aug 02 10:49:13 2016 +0200
@@ -65,6 +65,10 @@
         <default/>
         <onCreateDefault/>
       </column>
+      <column name="ISDEFAULT" primaryKey="false" required="true" type="CHAR" size="1" autoIncrement="false">
+        <default><![CDATA[N]]></default>
+        <onCreateDefault/>
+      </column>
       <foreign-key foreignTable="AD_CLIENT" name="C_POC_DOCTYPE_TEMPLATE_AD_CLIE">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/model/triggers/C_POC_DOCTYPE_TEMPLATE_TRG.xml	Tue Aug 02 10:49:13 2016 +0200
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+  <database name="TRIGGER C_POC_DOCTYPE_TEMPLATE_TRG">
+    <trigger name="C_POC_DOCTYPE_TEMPLATE_TRG" table="C_POC_DOCTYPE_TEMPLATE" fires="after" insert="true" update="true" delete="false" foreach="statement">
+      <body><![CDATA[
+ /*************************************************************************
+  * The contents of this file are subject to the Openbravo  Public  License
+  * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+  * Version 1.1  with a permitted attribution clause; you may not  use this
+  * file except in compliance with the License. You  may  obtain  a copy of
+  * the License at http://www.openbravo.com/legal/license.html
+  * Software distributed under the License  is  distributed  on  an "AS IS"
+  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+  * License for the specific  language  governing  rights  and  limitations
+  * under the License.
+  * The Original Code is Openbravo ERP.
+  * The Initial Developer of the Original Code is Openbravo SLU
+  * All portions are Copyright (C) 2016 Openbravo SLU
+  * All Rights Reserved.
+  * Contributor(s):  ______________________________________.
+  ************************************************************************/
+
+   v_count NUMBER;
+
+ BEGIN
+
+   IF AD_isTriggerEnabled()='N' THEN RETURN;
+   END IF;
+
+   -- Get number of document types with multiple templates marked as default
+   SELECT COUNT(*) INTO v_count
+   FROM dual
+   WHERE EXISTS (SELECT 1
+                 FROM c_poc_doctype_template
+                 WHERE isdefault = 'Y'
+                 GROUP BY c_doctype_id HAVING COUNT(*) > 1);
+
+   IF v_count > 0 THEN
+     RAISE_APPLICATION_ERROR(-20000, '@DuplicatedDefaults@');
+   END IF;
+
+ END C_POC_DOCTYPE_TEMPLATE_TRG
+]]></body>
+    </trigger>
+  </database>
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Mon Aug 01 13:21:44 2016 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Tue Aug 02 10:49:13 2016 +0200
@@ -349366,6 +349366,45 @@
 <!--BD308BA8925848BF995BC02631A8F5BB-->  <ALLOWED_CROSS_ORG_LINK><![CDATA[N]]></ALLOWED_CROSS_ORG_LINK>
 <!--BD308BA8925848BF995BC02631A8F5BB--></AD_COLUMN>
 
+<!--BD3122BF968E482B8B8747CF7126BC5A--><AD_COLUMN>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <AD_COLUMN_ID><![CDATA[BD3122BF968E482B8B8747CF7126BC5A]]></AD_COLUMN_ID>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <NAME><![CDATA[Isdefault]]></NAME>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <DESCRIPTION><![CDATA[A value that is shown whenever a record is created.]]></DESCRIPTION>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <HELP><![CDATA[The Default Checkbox indicates if this record will be used as a default value.]]></HELP>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <COLUMNNAME><![CDATA[Isdefault]]></COLUMNNAME>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <AD_TABLE_ID><![CDATA[1000500001]]></AD_TABLE_ID>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <FIELDLENGTH><![CDATA[1]]></FIELDLENGTH>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <DEFAULTVALUE><![CDATA[N]]></DEFAULTVALUE>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <SEQNO><![CDATA[170]]></SEQNO>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <AD_ELEMENT_ID><![CDATA[1103]]></AD_ELEMENT_ID>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <POSITION><![CDATA[17]]></POSITION>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ALLOWSORTING><![CDATA[Y]]></ALLOWSORTING>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ALLOWFILTERING><![CDATA[Y]]></ALLOWFILTERING>
+<!--BD3122BF968E482B8B8747CF7126BC5A-->  <ALLOWED_CROSS_ORG_LINK><![CDATA[N]]></ALLOWED_CROSS_ORG_LINK>
+<!--BD3122BF968E482B8B8747CF7126BC5A--></AD_COLUMN>
+
 <!--BD4D0980F314451086F4A861BD92C25E--><AD_COLUMN>
 <!--BD4D0980F314451086F4A861BD92C25E-->  <AD_COLUMN_ID><![CDATA[BD4D0980F314451086F4A861BD92C25E]]></AD_COLUMN_ID>
 <!--BD4D0980F314451086F4A861BD92C25E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Mon Aug 01 13:21:44 2016 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Tue Aug 02 10:49:13 2016 +0200
@@ -237429,6 +237429,35 @@
 <!--7A95551B78214EC593A6ECE75023DE4A-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--7A95551B78214EC593A6ECE75023DE4A--></AD_FIELD>
 
+<!--7A9B164A52CA41D2A93F1043BA6A888F--><AD_FIELD>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <AD_FIELD_ID><![CDATA[7A9B164A52CA41D2A93F1043BA6A888F]]></AD_FIELD_ID>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <NAME><![CDATA[Default]]></NAME>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <DESCRIPTION><![CDATA[A value that is shown whenever a record is created.]]></DESCRIPTION>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <HELP><![CDATA[The Default Checkbox indicates if this record will be used as a default value.]]></HELP>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <AD_TAB_ID><![CDATA[1000500001]]></AD_TAB_ID>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <AD_COLUMN_ID><![CDATA[BD3122BF968E482B8B8747CF7126BC5A]]></AD_COLUMN_ID>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <SEQNO><![CDATA[90]]></SEQNO>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <GRID_SEQNO><![CDATA[80]]></GRID_SEQNO>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--7A9B164A52CA41D2A93F1043BA6A888F-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--7A9B164A52CA41D2A93F1043BA6A888F--></AD_FIELD>
+
 <!--7A9D145141994C22A571BF26D57F684A--><AD_FIELD>
 <!--7A9D145141994C22A571BF26D57F684A-->  <AD_FIELD_ID><![CDATA[7A9D145141994C22A571BF26D57F684A]]></AD_FIELD_ID>
 <!--7A9D145141994C22A571BF26D57F684A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/utility/reporting/Template_data.xsql	Mon Aug 01 13:21:44 2016 +0200
+++ b/src/org/openbravo/erpCommon/utility/reporting/Template_data.xsql	Tue Aug 02 10:49:13 2016 +0200
@@ -71,7 +71,8 @@
 			documenttemplate.c_doctype_id = ? and
 			ad_isorgincluded(?,documenttemplate.ad_org_id,documenttemplate.ad_client_id)<>-1 and
 			documenttemplate.isactive = 'Y'
-		order by ad_isorgincluded(?,documenttemplate.ad_org_id,documenttemplate.ad_client_id) desc
+		order by documenttemplate.isdefault desc,
+		         ad_isorgincluded(?,documenttemplate.ad_org_id,documenttemplate.ad_client_id) desc
         ]]>
         </Sql>
         <Parameter name="docTypeId"/>