fixed bug 19558: automatic sequence does not work for value columns
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 10 Feb 2012 09:39:21 +0100
changeset 15416 510b3564269c
parent 15415 c8bbab77e329
child 15417 6aac6df29615
fixed bug 19558: automatic sequence does not work for value columns

Added a new flag to column to determine wether value column should use
automatic sequence.
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/SetDocumentNoHandler.java
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
src-db/database/model/tables/AD_COLUMN.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_ELEMENT.xml
src-db/database/sourcedata/AD_FIELD.xml
src/org/openbravo/base/model/Column.hbm.xml
src/org/openbravo/base/model/Column.java
src/org/openbravo/base/model/Property.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/SetDocumentNoHandler.java	Fri Feb 10 08:49:15 2012 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/SetDocumentNoHandler.java	Fri Feb 10 09:39:21 2012 +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) 2011 Openbravo SLU 
+ * All portions are Copyright (C) 2011-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -119,8 +119,7 @@
       List<Property> processedPropertyList = new ArrayList<Property>();
       for (Entity entity : ModelProvider.getInstance().getModel()) {
         for (Property prop : entity.getProperties()) {
-          if ("documentno".equals(prop.getColumnName() != null ? prop.getColumnName().toLowerCase()
-              : "")) {
+          if (prop.isUsedSequence()) {
             entityList.add(entity);
             documentNoPropertyList.add(prop);
             if (entity.hasProperty(Order.PROPERTY_DOCUMENTTYPE)) {
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java	Fri Feb 10 08:49:15 2012 +0100
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java	Fri Feb 10 09:39:21 2012 +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) 2010-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -150,7 +150,9 @@
       columnValue = rq.getRequestParameter("inp"
           + Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName()));
     } else {
-      if (field.getColumn().getDBColumnName().equalsIgnoreCase("documentno")) {
+      if (field.getColumn().getDBColumnName().equalsIgnoreCase("documentno")
+          || (field.getColumn().isUseAutomaticSequence() && field.getColumn().getDBColumnName()
+              .equals("Value"))) {
         String docTypeTarget = rq.getRequestParameter("inp"
             + Sqlc.TransformaNombreColumna("C_DocTypeTarget_ID"));
         if (docTypeTarget == null)
--- a/src-db/database/model/tables/AD_COLUMN.xml	Fri Feb 10 08:49:15 2012 +0100
+++ b/src-db/database/model/tables/AD_COLUMN.xml	Fri Feb 10 09:39:21 2012 +0100
@@ -197,6 +197,10 @@
         <default/>
         <onCreateDefault/>
       </column>
+      <column name="ISUSEDSEQUENCE" primaryKey="false" required="true" type="CHAR" size="1" autoIncrement="false">
+        <default><![CDATA[N]]></default>
+        <onCreateDefault><![CDATA['N']]></onCreateDefault>
+      </column>
       <foreign-key foreignTable="AD_CALLOUT" name="AD_COLUMN_AD_CALLOUT">
         <reference local="AD_CALLOUT_ID" foreign="AD_CALLOUT_ID"/>
       </foreign-key>
@@ -249,5 +253,6 @@
       <check name="AD_COLUMN_ISSELECTIONCOLUM_CHK"><![CDATA[ISSELECTIONCOLUMN IN ('Y', 'N')]]></check>
       <check name="AD_COLUMN_ISTRANSLATED_CHK"><![CDATA[ISTRANSLATED IN ('Y', 'N')]]></check>
       <check name="AD_COLUMN_ISUPDATEABLE_CHK"><![CDATA[ISUPDATEABLE IN ('Y', 'N')]]></check>
+      <check name="AD_COLUMN_USEDSEQ_CHK"><![CDATA[ISUSEDSEQUENCE IN ('Y', 'N')]]></check>
     </table>
   </database>
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Fri Feb 10 08:49:15 2012 +0100
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Fri Feb 10 09:39:21 2012 +0100
@@ -277461,6 +277461,41 @@
 <!--F0DC1E59056A43CA9FFC55DAFCA74B94-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
 <!--F0DC1E59056A43CA9FFC55DAFCA74B94--></AD_COLUMN>
 
+<!--F13FEE71CE5046C19A2E1D457C970F30--><AD_COLUMN>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <AD_COLUMN_ID><![CDATA[F13FEE71CE5046C19A2E1D457C970F30]]></AD_COLUMN_ID>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <NAME><![CDATA[Use Automatic Sequence]]></NAME>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <DESCRIPTION><![CDATA[Use Automatic Sequence]]></DESCRIPTION>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <HELP><![CDATA[Column which DB column name is "Value", can use automatic sequence numbers, to do so this check needs to be marked. When a "Value" column uses automatic sequence works in a similar way document number columns work: when user creates a new record the default value is based in the next available sequence number (based on the sequence for the table).]]></HELP>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <COLUMNNAME><![CDATA[IsUsedSequence]]></COLUMNNAME>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <AD_TABLE_ID><![CDATA[101]]></AD_TABLE_ID>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <FIELDLENGTH><![CDATA[1]]></FIELDLENGTH>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <DEFAULTVALUE><![CDATA[N]]></DEFAULTVALUE>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <SEQNO><![CDATA[171]]></SEQNO>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <AD_ELEMENT_ID><![CDATA[8769BF2DBAED417E95CB5F5B31DC851A]]></AD_ELEMENT_ID>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <POSITION><![CDATA[51]]></POSITION>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--F13FEE71CE5046C19A2E1D457C970F30-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--F13FEE71CE5046C19A2E1D457C970F30--></AD_COLUMN>
+
 <!--F14FEA351BD34240B9F741CC2CDFED5B--><AD_COLUMN>
 <!--F14FEA351BD34240B9F741CC2CDFED5B-->  <AD_COLUMN_ID><![CDATA[F14FEA351BD34240B9F741CC2CDFED5B]]></AD_COLUMN_ID>
 <!--F14FEA351BD34240B9F741CC2CDFED5B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_ELEMENT.xml	Fri Feb 10 08:49:15 2012 +0100
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml	Fri Feb 10 09:39:21 2012 +0100
@@ -26143,6 +26143,20 @@
 <!--86DF1B3B331B03FEE040007F0101757D-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--86DF1B3B331B03FEE040007F0101757D--></AD_ELEMENT>
 
+<!--8769BF2DBAED417E95CB5F5B31DC851A--><AD_ELEMENT>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <AD_ELEMENT_ID><![CDATA[8769BF2DBAED417E95CB5F5B31DC851A]]></AD_ELEMENT_ID>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <COLUMNNAME><![CDATA[IsUsedSequence]]></COLUMNNAME>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <NAME><![CDATA[Use Automatic Sequence]]></NAME>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <PRINTNAME><![CDATA[Use Automatic Sequence]]></PRINTNAME>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <DESCRIPTION><![CDATA[Use Automatic Sequence]]></DESCRIPTION>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <HELP><![CDATA[Column which DB column name is "Value", can use automatic sequence numbers, to do so this check needs to be marked. When a "Value" column uses automatic sequence works in a similar way document number columns work: when user creates a new record the default value is based in the next available sequence number (based on the sequence for the table).]]></HELP>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--8769BF2DBAED417E95CB5F5B31DC851A-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--8769BF2DBAED417E95CB5F5B31DC851A--></AD_ELEMENT>
+
 <!--876CE05E803188E4E040007F0100789B--><AD_ELEMENT>
 <!--876CE05E803188E4E040007F0100789B-->  <AD_ELEMENT_ID><![CDATA[876CE05E803188E4E040007F0100789B]]></AD_ELEMENT_ID>
 <!--876CE05E803188E4E040007F0100789B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Fri Feb 10 08:49:15 2012 +0100
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Fri Feb 10 09:39:21 2012 +0100
@@ -210055,6 +210055,33 @@
 <!--C98A9A0AC35A4F5E9F73E6E2A3CC0F9C-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
 <!--C98A9A0AC35A4F5E9F73E6E2A3CC0F9C--></AD_FIELD>
 
+<!--C9BDCE5245E64DDD998DB763235BC15E--><AD_FIELD>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <AD_FIELD_ID><![CDATA[C9BDCE5245E64DDD998DB763235BC15E]]></AD_FIELD_ID>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <NAME><![CDATA[Use Automatic Sequence]]></NAME>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <DESCRIPTION><![CDATA[Use Automatic Sequence]]></DESCRIPTION>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <HELP><![CDATA[Column which DB column name is "Value", can use automatic sequence numbers, to do so this check needs to be marked. When a "Value" column uses automatic sequence works in a similar way document number columns work: when user creates a new record the default value is based in the next available sequence number (based on the sequence for the table).]]></HELP>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <AD_TAB_ID><![CDATA[101]]></AD_TAB_ID>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <AD_COLUMN_ID><![CDATA[F13FEE71CE5046C19A2E1D457C970F30]]></AD_COLUMN_ID>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <DISPLAYLOGIC><![CDATA[@ColumnName@='Value']]></DISPLAYLOGIC>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <SEQNO><![CDATA[350]]></SEQNO>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--C9BDCE5245E64DDD998DB763235BC15E-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--C9BDCE5245E64DDD998DB763235BC15E--></AD_FIELD>
+
 <!--C9F0FE067F9A4D20A0D84D6D43865BC2--><AD_FIELD>
 <!--C9F0FE067F9A4D20A0D84D6D43865BC2-->  <AD_FIELD_ID><![CDATA[C9F0FE067F9A4D20A0D84D6D43865BC2]]></AD_FIELD_ID>
 <!--C9F0FE067F9A4D20A0D84D6D43865BC2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/base/model/Column.hbm.xml	Fri Feb 10 08:49:15 2012 +0100
+++ b/src/org/openbravo/base/model/Column.hbm.xml	Fri Feb 10 09:39:21 2012 +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) 2008-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -46,7 +46,8 @@
 		<property name="valueMax"/>
 		<property name="developmentStatus"/>
 		<property name="position"/>
-	    <property name="seqno"/>	
+	    <property name="seqno"/>
+        <property name="usedSequence" type="org.openbravo.base.session.OBYesNoType" column="isusedsequence"/>
     
 		<many-to-one name="table" not-null="true" class="org.openbravo.base.model.Table" column="ad_table_id"/>
 		 
--- a/src/org/openbravo/base/model/Column.java	Fri Feb 10 08:49:15 2012 +0100
+++ b/src/org/openbravo/base/model/Column.java	Fri Feb 10 09:39:21 2012 +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) 2008-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -68,6 +68,7 @@
   private Integer position;
   private boolean translatable;
   private Integer seqno;
+  private boolean usedSequence;
 
   private Module module;
 
@@ -463,4 +464,12 @@
   public void setSeqno(Integer seqno) {
     this.seqno = seqno;
   }
+
+  public boolean isUsedSequence() {
+    return usedSequence;
+  }
+
+  public void setUsedSequence(boolean usedSequence) {
+    this.usedSequence = usedSequence;
+  }
 }
--- a/src/org/openbravo/base/model/Property.java	Fri Feb 10 08:49:15 2012 +0100
+++ b/src/org/openbravo/base/model/Property.java	Fri Feb 10 09:39:21 2012 +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) 2008-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -117,6 +117,7 @@
   private Property trlOneToManyProperty;
 
   private Integer seqno;
+  private boolean usedSequence;
 
   /**
    * Initializes this Property using the information from the Column.
@@ -137,6 +138,7 @@
     setStoredInSession(fromColumn.isStoredInSession());
 
     setDomainType(fromColumn.getDomainType());
+    setUsedSequence(fromColumn.isUsedSequence());
 
     // if one of the old hardcoded pwd-column -> move to new-style reference
     // Companion-code in UIDefinitionController (for for UIDefinition)
@@ -1240,4 +1242,14 @@
   public void setSeqno(Integer seqno) {
     this.seqno = seqno;
   }
+
+  public boolean isUsedSequence() {
+    return usedSequence;
+  }
+
+  public void setUsedSequence(boolean usedSequence) {
+    this.usedSequence = "documentno".equalsIgnoreCase(columnName)
+        || (usedSequence && "Value".equals(columnName));
+    ;
+  }
 }