# HG changeset patch
# User Silambarasan Sekar <silambarasan@qualiantech.com>
# Date 1456997141 -19800
#      Thu Mar 03 14:55:41 2016 +0530
# Node ID e20983d3cf8d66042e0f1b8aae9d162c4986754f
# Parent  962eab45efce69ff95aed5bf4214c68da6f1c0a3
Fixes issue 32405:Ability to have a separate prefix and sequence for return documents

diff -r 962eab45efce -r e20983d3cf8d src-db/database/model/tables/OBPOS_APPLICATIONS.xml
--- a/src-db/database/model/tables/OBPOS_APPLICATIONS.xml	Thu Mar 03 08:00:49 2016 -0600
+++ b/src-db/database/model/tables/OBPOS_APPLICATIONS.xml	Thu Mar 03 14:55:41 2016 +0530
@@ -109,6 +109,14 @@
         <default/>
         <onCreateDefault/>
       </column>
+      <column name="RETURNDOCNO_PREFIX" primaryKey="false" required="false" type="VARCHAR" size="60" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="RETURNSLASTASSIGNEDNUM" primaryKey="false" required="false" type="DECIMAL" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
       <foreign-key foreignTable="AD_CLIENT" name="OBPOS_APP_AD_CLIENT">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
diff -r 962eab45efce -r e20983d3cf8d src-db/database/sourcedata/AD_COLUMN.xml
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Thu Mar 03 08:00:49 2016 -0600
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Thu Mar 03 14:55:41 2016 +0530
@@ -9441,6 +9441,42 @@
 <!--AFF5C3E0A2334A2F9D2A08ACCF06D60A-->  <ALLOWFILTERING><![CDATA[Y]]></ALLOWFILTERING>
 <!--AFF5C3E0A2334A2F9D2A08ACCF06D60A--></AD_COLUMN>
 
+<!--B1BAB56967304DB2B843A24C6E6632FF--><AD_COLUMN>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <AD_COLUMN_ID><![CDATA[B1BAB56967304DB2B843A24C6E6632FF]]></AD_COLUMN_ID>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <NAME><![CDATA[Returndocno_Prefix]]></NAME>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <HELP><![CDATA[This is the prefix added to the document number for Returns.]]></HELP>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <COLUMNNAME><![CDATA[Returndocno_Prefix]]></COLUMNNAME>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <AD_TABLE_ID><![CDATA[FF80818132F311740132F31E2C9A0016]]></AD_TABLE_ID>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <AD_REFERENCE_ID><![CDATA[10]]></AD_REFERENCE_ID>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <FIELDLENGTH><![CDATA[60]]></FIELDLENGTH>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <SEQNO><![CDATA[480]]></SEQNO>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <AD_ELEMENT_ID><![CDATA[7BFC281DE4C344BAAEA4097B4C54A46A]]></AD_ELEMENT_ID>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <POSITION><![CDATA[28]]></POSITION>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ALLOWSORTING><![CDATA[Y]]></ALLOWSORTING>
+<!--B1BAB56967304DB2B843A24C6E6632FF-->  <ALLOWFILTERING><![CDATA[Y]]></ALLOWFILTERING>
+<!--B1BAB56967304DB2B843A24C6E6632FF--></AD_COLUMN>
+
 <!--B3C50444835F4AD6AF62C0F98D04CD6D--><AD_COLUMN>
 <!--B3C50444835F4AD6AF62C0F98D04CD6D-->  <AD_COLUMN_ID><![CDATA[B3C50444835F4AD6AF62C0F98D04CD6D]]></AD_COLUMN_ID>
 <!--B3C50444835F4AD6AF62C0F98D04CD6D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -11499,6 +11535,41 @@
 <!--DC439C74106745A1A63B851CCC3F33BA-->  <ALLOWFILTERING><![CDATA[Y]]></ALLOWFILTERING>
 <!--DC439C74106745A1A63B851CCC3F33BA--></AD_COLUMN>
 
+<!--DC7FDB69BC1D4D979722549567A8A116--><AD_COLUMN>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <AD_COLUMN_ID><![CDATA[DC7FDB69BC1D4D979722549567A8A116]]></AD_COLUMN_ID>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <NAME><![CDATA[Returnslastassignednum]]></NAME>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <COLUMNNAME><![CDATA[Returnslastassignednum]]></COLUMNNAME>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <AD_TABLE_ID><![CDATA[FF80818132F311740132F31E2C9A0016]]></AD_TABLE_ID>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <SEQNO><![CDATA[490]]></SEQNO>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <AD_ELEMENT_ID><![CDATA[D9B75688064E48CFB4FCC98DAA4B7A46]]></AD_ELEMENT_ID>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <POSITION><![CDATA[29]]></POSITION>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ALLOWSORTING><![CDATA[Y]]></ALLOWSORTING>
+<!--DC7FDB69BC1D4D979722549567A8A116-->  <ALLOWFILTERING><![CDATA[Y]]></ALLOWFILTERING>
+<!--DC7FDB69BC1D4D979722549567A8A116--></AD_COLUMN>
+
 <!--DCAE4BC889F44527B9F7414EC6094E3D--><AD_COLUMN>
 <!--DCAE4BC889F44527B9F7414EC6094E3D-->  <AD_COLUMN_ID><![CDATA[DCAE4BC889F44527B9F7414EC6094E3D]]></AD_COLUMN_ID>
 <!--DCAE4BC889F44527B9F7414EC6094E3D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 962eab45efce -r e20983d3cf8d src-db/database/sourcedata/AD_ELEMENT.xml
--- a/src-db/database/sourcedata/AD_ELEMENT.xml	Thu Mar 03 08:00:49 2016 -0600
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml	Thu Mar 03 14:55:41 2016 +0530
@@ -1114,6 +1114,19 @@
 <!--79160EA002E24CE686C91226AEF1CBAF-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--79160EA002E24CE686C91226AEF1CBAF--></AD_ELEMENT>
 
+<!--7BFC281DE4C344BAAEA4097B4C54A46A--><AD_ELEMENT>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <AD_ELEMENT_ID><![CDATA[7BFC281DE4C344BAAEA4097B4C54A46A]]></AD_ELEMENT_ID>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <COLUMNNAME><![CDATA[Returndocno_Prefix]]></COLUMNNAME>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <NAME><![CDATA[Returndocno_Prefix]]></NAME>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <PRINTNAME><![CDATA[Returndocno_Prefix]]></PRINTNAME>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <HELP><![CDATA[This is the prefix added to the document number for Returns.]]></HELP>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--7BFC281DE4C344BAAEA4097B4C54A46A--></AD_ELEMENT>
+
 <!--7DE76BA4257C4236B5F0D7C530C92133--><AD_ELEMENT>
 <!--7DE76BA4257C4236B5F0D7C530C92133-->  <AD_ELEMENT_ID><![CDATA[7DE76BA4257C4236B5F0D7C530C92133]]></AD_ELEMENT_ID>
 <!--7DE76BA4257C4236B5F0D7C530C92133-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1909,6 +1922,18 @@
 <!--D8E69F36089F475BAA85F447EA01D580-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--D8E69F36089F475BAA85F447EA01D580--></AD_ELEMENT>
 
+<!--D9B75688064E48CFB4FCC98DAA4B7A46--><AD_ELEMENT>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <AD_ELEMENT_ID><![CDATA[D9B75688064E48CFB4FCC98DAA4B7A46]]></AD_ELEMENT_ID>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <COLUMNNAME><![CDATA[Returnslastassignednum]]></COLUMNNAME>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <NAME><![CDATA[Returnslastassignednum]]></NAME>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <PRINTNAME><![CDATA[Returnslastassignednum]]></PRINTNAME>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--D9B75688064E48CFB4FCC98DAA4B7A46--></AD_ELEMENT>
+
 <!--DA705E89C1C34B5DBF646A5D1C16A517--><AD_ELEMENT>
 <!--DA705E89C1C34B5DBF646A5D1C16A517-->  <AD_ELEMENT_ID><![CDATA[DA705E89C1C34B5DBF646A5D1C16A517]]></AD_ELEMENT_ID>
 <!--DA705E89C1C34B5DBF646A5D1C16A517-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 962eab45efce -r e20983d3cf8d src-db/database/sourcedata/AD_FIELD.xml
--- a/src-db/database/sourcedata/AD_FIELD.xml	Thu Mar 03 08:00:49 2016 -0600
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Thu Mar 03 14:55:41 2016 +0530
@@ -7432,6 +7432,35 @@
 <!--E4641870AEC84A8D8E76A3B55DB18FE0-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--E4641870AEC84A8D8E76A3B55DB18FE0--></AD_FIELD>
 
+<!--E5E7A93A9A1D4174A43278D7E0E04C14--><AD_FIELD>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <AD_FIELD_ID><![CDATA[E5E7A93A9A1D4174A43278D7E0E04C14]]></AD_FIELD_ID>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <NAME><![CDATA[Return No Prefix]]></NAME>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <DESCRIPTION><![CDATA[Return No Prefix]]></DESCRIPTION>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <HELP><![CDATA[This is the prefix added to the document number for Returns.]]></HELP>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISCENTRALLYMAINTAINED><![CDATA[N]]></ISCENTRALLYMAINTAINED>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <AD_TAB_ID><![CDATA[FF80818132F311740132F3233778004B]]></AD_TAB_ID>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <AD_COLUMN_ID><![CDATA[B1BAB56967304DB2B843A24C6E6632FF]]></AD_COLUMN_ID>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <DISPLAYLENGTH><![CDATA[60]]></DISPLAYLENGTH>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <SEQNO><![CDATA[77]]></SEQNO>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <GRID_SEQNO><![CDATA[0]]></GRID_SEQNO>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--E5E7A93A9A1D4174A43278D7E0E04C14--></AD_FIELD>
+
 <!--E5EBCFED984240BCA9842D21A8380349--><AD_FIELD>
 <!--E5EBCFED984240BCA9842D21A8380349-->  <AD_FIELD_ID><![CDATA[E5EBCFED984240BCA9842D21A8380349]]></AD_FIELD_ID>
 <!--E5EBCFED984240BCA9842D21A8380349-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 962eab45efce -r e20983d3cf8d src/org/openbravo/retail/posterminal/OrderLoader.java
--- a/src/org/openbravo/retail/posterminal/OrderLoader.java	Thu Mar 03 08:00:49 2016 -0600
+++ b/src/org/openbravo/retail/posterminal/OrderLoader.java	Thu Mar 03 14:55:41 2016 +0530
@@ -1463,6 +1463,13 @@
           terminal.setQuotationslastassignednum(documentno);
           OBDal.getInstance().save(terminal);
         }
+      } else if (jsonorder.has("isReturn") && jsonorder.getBoolean("isReturn")) {
+        if (order.getObposApplications().getReturnslastassignednum() == null
+            || documentno > order.getObposApplications().getReturnslastassignednum()) {
+          OBPOSApplications terminal = order.getObposApplications();
+          terminal.setReturnslastassignednum(documentno);
+          OBDal.getInstance().save(terminal);
+        }
       } else {
         if (order.getObposApplications().getLastassignednum() == null
             || documentno > order.getObposApplications().getLastassignednum()) {
diff -r 962eab45efce -r e20983d3cf8d src/org/openbravo/retail/posterminal/POSUtils.java
--- a/src/org/openbravo/retail/posterminal/POSUtils.java	Thu Mar 03 08:00:49 2016 -0600
+++ b/src/org/openbravo/retail/posterminal/POSUtils.java	Thu Mar 03 14:55:41 2016 +0530
@@ -468,6 +468,86 @@
     return maxDocNo;
   }
 
+  public static int getLastDocumentNumberReturnForPOS(String searchKey, List<String> documentTypeIds) {
+    OBCriteria<OBPOSApplications> termCrit = OBDal.getInstance().createCriteria(
+        OBPOSApplications.class);
+    termCrit.add(Restrictions.eq(OBPOSApplications.PROPERTY_SEARCHKEY, searchKey));
+    if (termCrit.count() != 1) {
+      throw new OBException("Error while loading the terminal " + searchKey);
+    }
+    OBPOSApplications terminal = (OBPOSApplications) termCrit.uniqueResult();
+
+    String curDbms = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty("bbdd.rdbms");
+    String sqlToExecute;
+    String doctypeIds = "";
+    for (String doctypeId : documentTypeIds) {
+      if (!doctypeIds.equals("")) {
+        doctypeIds += ",";
+      }
+      doctypeIds += "'" + doctypeId + "'";
+    }
+    int maxDocNo;
+    Long returnlastDocNum = terminal.getReturnslastassignednum();
+    if (returnlastDocNum == null) {
+      if (curDbms.equals("POSTGRE")) {
+        sqlToExecute = "select max(a.docno) from (select to_number(substring(documentno, '/([0-9]+)$')) docno from c_order where em_obpos_applications_id= (select obpos_applications_id from obpos_applications where value = ?) and c_doctype_id in ("
+            + doctypeIds
+            + ") and documentno like (select returndocno_prefix from obpos_applications where value = ?)||'%') a";
+      } else if (curDbms.equals("ORACLE")) {
+        sqlToExecute = "select max(a.docno) from (select to_number(substr(REGEXP_SUBSTR(documentno, '/([0-9]+)$'), 2)) docno from c_order where em_obpos_applications_id= (select obpos_applications_id from obpos_applications where value = ?) and c_doctype_id in ("
+            + doctypeIds
+            + ") and documentno like (select returndocno_prefix from obpos_applications where value = ?)||'%' ) a";
+      } else {
+        // unknow DBMS
+        // shouldn't happen
+        log.error("Error getting max documentNo because the DBMS is unknown.");
+        return 0;
+      }
+      SQLQuery query = OBDal.getInstance().getSession().createSQLQuery(sqlToExecute);
+      query.setString(0, searchKey);
+      query.setString(1, searchKey);
+      Object result = query.uniqueResult();
+      if (result == null) {
+        maxDocNo = 0;
+      } else if (curDbms.equals("POSTGRE")) {
+        maxDocNo = ((BigDecimal) result).intValue();
+      } else if (curDbms.equals("ORACLE")) {
+        maxDocNo = ((Long) result).intValue();
+      } else {
+        maxDocNo = 0;
+      }
+    } else {
+      maxDocNo = returnlastDocNum.intValue();
+    }
+
+    // This number will be compared against the maximum number of the failed orders
+    OBCriteria<OBPOSErrors> errorCrit = OBDal.getInstance().createCriteria(OBPOSErrors.class);
+    errorCrit.add(Restrictions.eq(OBPOSErrors.PROPERTY_OBPOSAPPLICATIONS, terminal));
+    errorCrit.add(Restrictions.eq(OBPOSErrors.PROPERTY_TYPEOFDATA, "Order"));
+    List<OBPOSErrors> errors = errorCrit.list();
+    for (OBPOSErrors error : errors) {
+      try {
+        JSONObject jsonError = new JSONObject(error.getJsoninfo());
+        if (jsonError.has("documentNo") && jsonError.has("isReturn")
+            && jsonError.getBoolean("isReturn")) {
+          String documentNo = jsonError.getString("documentNo");
+          if (documentNo.indexOf("/") != 0) {
+            String number = documentNo.substring(documentNo.indexOf("/") + 1);
+            int errorNumber = new Long(number).intValue();
+            if (errorNumber > maxDocNo) {
+              maxDocNo = errorNumber;
+            }
+          }
+        }
+      } catch (Exception e) {
+        e.printStackTrace();
+        // If not parseable, we continue
+      }
+    }
+    return maxDocNo;
+  }
+
   public static int getLastDocumentNumberForPOS(String searchKey, String documentTypeId) {
     ArrayList<String> doctypeId = new ArrayList<String>();
     doctypeId.add(documentTypeId);
@@ -482,6 +562,13 @@
 
   }
 
+  public static int getLastDocumentNumberReturnForPOS(String searchKey, String documentTypeId) {
+    ArrayList<String> doctypeId = new ArrayList<String>();
+    doctypeId.add(documentTypeId);
+    return getLastDocumentNumberReturnForPOS(searchKey, doctypeId);
+
+  }
+
   public static void getRetailDependantModules(Module module, List<Module> moduleList,
       List<ModuleDependency> list) {
     for (ModuleDependency depModule : list) {
diff -r 962eab45efce -r e20983d3cf8d src/org/openbravo/retail/posterminal/term/Terminal.java
--- a/src/org/openbravo/retail/posterminal/term/Terminal.java	Thu Mar 03 08:00:49 2016 -0600
+++ b/src/org/openbravo/retail/posterminal/term/Terminal.java	Thu Mar 03 14:55:41 2016 +0530
@@ -76,9 +76,13 @@
       String quotationsDocTypeId = pOSTerminal.getObposTerminaltype()
           .getDocumentTypeForQuotations() == null ? null : pOSTerminal.getObposTerminaltype()
           .getDocumentTypeForQuotations().getId();
+      // saving returns doc id to prevent session to be lost in getLastDocumentNumberForPOS
+      String returnsDocTypeId = pOSTerminal.getObposTerminaltype().getDocumentTypeForReturns()
+          .getId();
       List<String> doctypeIds = new ArrayList<String>();
       doctypeIds.add(pOSTerminal.getObposTerminaltype().getDocumentType().getId());
-      doctypeIds.add(pOSTerminal.getObposTerminaltype().getDocumentTypeForReturns().getId());
+      if (pOSTerminal.getReturndocnoPrefix() == null)
+        doctypeIds.add(pOSTerminal.getObposTerminaltype().getDocumentTypeForReturns().getId());
       int lastDocumentNumber = POSUtils.getLastDocumentNumberForPOS(pOSTerminal.getSearchKey(),
           doctypeIds);
       int lastQuotationDocumentNumber = 0;
@@ -86,6 +90,11 @@
         lastQuotationDocumentNumber = POSUtils.getLastDocumentNumberQuotationForPOS(
             pOSTerminal.getSearchKey(), quotationsDocTypeId);
       }
+      int lastReturnDocumentNumber = 0;
+      if (returnsDocTypeId != null) {
+        lastReturnDocumentNumber = POSUtils.getLastDocumentNumberReturnForPOS(
+            pOSTerminal.getSearchKey(), returnsDocTypeId);
+      }
       String warehouseId = POSUtils.getWarehouseForTerminal(pOSTerminal).getId();
       final org.openbravo.model.pricing.pricelist.PriceList pricesList = POSUtils
           .getPriceListByTerminal(pOSTerminal.getSearchKey());
@@ -145,8 +154,9 @@
           + "' as currencySymbolAtTheRight, " + "'" + pricesList.getCurrency().getSymbol()
           + "' as symbol, " + "'" + warehouseId + "' as warehouse, " + lastDocumentNumber
           + " as lastDocumentNumber, " + lastQuotationDocumentNumber
-          + " as lastQuotationDocumentNumber, " + "'" + regionId + "'"
-          + " as organizationRegionId, " + "'" + countryId + "'" + " as organizationCountryId, '"
+          + " as lastQuotationDocumentNumber, " + lastReturnDocumentNumber
+          + " as lastReturnDocumentNumber, " + "'" + regionId + "'" + " as organizationRegionId, "
+          + "'" + countryId + "'" + " as organizationCountryId, '"
           + ProcessHQLQuery.escape(storeAddress) + "' as organizationAddressIdentifier, "
           + sessionTimeout + " as sessionTimeout, " + selectOrgImage
           + regularTerminalHQLProperties.getHqlSelect()
diff -r 962eab45efce -r e20983d3cf8d src/org/openbravo/retail/posterminal/term/TerminalProperties.java
--- a/src/org/openbravo/retail/posterminal/term/TerminalProperties.java	Thu Mar 03 08:00:49 2016 -0600
+++ b/src/org/openbravo/retail/posterminal/term/TerminalProperties.java	Thu Mar 03 14:55:41 2016 +0530
@@ -67,6 +67,7 @@
     list.add(new HQLProperty("pos.orderdocnoPrefix", "docNoPrefix"));
     list.add(new HQLProperty("coalesce(pos.quotationdocnoPrefix, concat(pos.searchKey, 'QT'))",
         "quotationDocNoPrefix"));
+    list.add(new HQLProperty("pos.returndocnoPrefix", "returnDocNoPrefix"));
     list.add(new HQLProperty("pos.obposTerminaltype.allowpayoncredit", "allowpayoncredit"));
     list.add(new HQLProperty("pos.organization.obposCountDiffLimit", "organizationCountDiffLimit"));
     list.add(new HQLProperty("pos.defaultwebpostab", "defaultwebpostab"));
diff -r 962eab45efce -r e20983d3cf8d web/org.openbravo.retail.posterminal/js/closecash/view/tabpendingreceipts.js
--- a/web/org.openbravo.retail.posterminal/js/closecash/view/tabpendingreceipts.js	Thu Mar 03 08:00:49 2016 -0600
+++ b/web/org.openbravo.retail.posterminal/js/closecash/view/tabpendingreceipts.js	Thu Mar 03 14:55:41 2016 +0530
@@ -182,7 +182,7 @@
     }
     model.set('hasbeenpaid', 'Y');
     model.save();
-    OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(model.get('documentnoSuffix'), model.get('quotationnoSuffix'), function () {
+    OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(model.get('documentnoSuffix'), model.get('quotationnoSuffix'), model.get('returnnoSuffix'), function () {
       me.collection.remove(model);
     });
   },
diff -r 962eab45efce -r e20983d3cf8d web/org.openbravo.retail.posterminal/js/components/menu.js
--- a/web/org.openbravo.retail.posterminal/js/components/menu.js	Thu Mar 03 08:00:49 2016 -0600
+++ b/web/org.openbravo.retail.posterminal/js/components/menu.js	Thu Mar 03 14:55:41 2016 +0530
@@ -26,6 +26,7 @@
       permission: this.permission,
       orderType: 1
     });
+    this.model.get('order').setReturnDocumentNo();
     if (OB.MobileApp.model.get('lastPaneShown') === 'payment') {
       this.model.get('order').trigger('scan');
     }
@@ -262,6 +263,13 @@
         me.updateVisibility(false);
       }
     }, this);
+    receipt.on('change:orderType', function (model) {
+      if (model.get('orderType') === 1) {
+        me.updateVisibility(false);
+      } else {
+        me.updateVisibility(true);
+      }
+    }, this);
     receipt.on('change:isEditable', function (newValue) {
       if (newValue) {
         if (newValue.get('isEditable') === false) {
diff -r 962eab45efce -r e20983d3cf8d web/org.openbravo.retail.posterminal/js/data/dataordersave.js
--- a/web/org.openbravo.retail.posterminal/js/data/dataordersave.js	Thu Mar 03 08:00:49 2016 -0600
+++ b/web/org.openbravo.retail.posterminal/js/data/dataordersave.js	Thu Mar 03 14:55:41 2016 +0530
@@ -158,7 +158,7 @@
           // when all the properties of the receipt have been set, keep a copy
           OB.UTIL.cashUpReport(receipt, function () {
             OB.UTIL.calculateCurrentCash(null, tx);
-            OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(receipt.get('documentnoSuffix'), receipt.get('quotationnoSuffix'), function () {
+            OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(receipt.get('documentnoSuffix'), receipt.get('quotationnoSuffix'), receipt.get('returnnoSuffix'), function () {
               OB.trace('Saving receipt.');
               OB.Dal.saveInTransaction(tx, receipt, function () {
                 // the trigger is fired on the receipt object, as there is only 1 that is being updated
@@ -274,7 +274,7 @@
       this.receipt.set('accountingDate', OB.I18N.normalizeDate(new Date()));
       this.receipt.set('hasbeenpaid', 'Y');
       this.context.get('multiOrders').trigger('integrityOk', this.receipt);
-      OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(this.receipt.get('documentnoSuffix'), this.receipt.get('quotationnoSuffix'));
+      OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(this.receipt.get('documentnoSuffix'), this.receipt.get('quotationnoSuffix'), this.receipt.get('returnnoSuffix'));
 
       delete this.receipt.attributes.json;
       this.receipt.set('timezoneOffset', creationDate.getTimezoneOffset());
diff -r 962eab45efce -r e20983d3cf8d web/org.openbravo.retail.posterminal/js/login/model/login-model.js
--- a/web/org.openbravo.retail.posterminal/js/login/model/login-model.js	Thu Mar 03 08:00:49 2016 -0600
+++ b/web/org.openbravo.retail.posterminal/js/login/model/login-model.js	Thu Mar 03 14:55:41 2016 +0530
@@ -144,7 +144,7 @@
               }
 
               // update the local database with the document sequence received
-              OB.MobileApp.model.saveDocumentSequence(OB.MobileApp.model.get('terminal').lastDocumentNumber, OB.MobileApp.model.get('terminal').lastQuotationDocumentNumber, function () {
+              OB.MobileApp.model.saveDocumentSequence(OB.MobileApp.model.get('terminal').lastDocumentNumber, OB.MobileApp.model.get('terminal').lastQuotationDocumentNumber, OB.MobileApp.model.get('terminal').lastReturnDocumentNumber, function () {
                 if (OB.MobileApp.model.orderList) {
                   OB.MobileApp.model.orderList.synchronizeCurrentOrder();
                 }
@@ -674,7 +674,7 @@
               model.get('lines').at(i).set('obposIsDeleted', true);
             }
             model.set('hasbeenpaid', 'Y');
-            OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(model.get('documentnoSuffix'), model.get('quotationnoSuffix'), function () {
+            OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(model.get('documentnoSuffix'), model.get('quotationnoSuffix'), model.get('returnnoSuffix'), function () {
               model.save(saveCallback);
             });
           });
@@ -712,12 +712,13 @@
     // they feed from the local database, and the server
     documentnoThreshold: -1,
     quotationnoThreshold: -1,
+    returnnoThreshold: -1,
     isSeqNoReadyEventSent: false,
     /**
      * Save the new values if are higher than the last known values
      * - the minimum sequence number can only grow
      */
-    saveDocumentSequence: function (documentnoSuffix, quotationnoSuffix, callback, tx) {
+    saveDocumentSequence: function (documentnoSuffix, quotationnoSuffix, returnnoSuffix, callback, tx) {
       var me = this;
 
       if (me.restartingDocNo === true) {
@@ -728,15 +729,15 @@
       }
 
       // if the document sequence is trying to be initialized but it has already been initialized, do nothing
-      if (documentnoSuffix === -1 && quotationnoSuffix === -1 && this.documentnoThreshold >= 0 && this.quotationnoThreshold >= 0) {
+      if (documentnoSuffix === -1 && quotationnoSuffix === -1 && returnnoSuffix === -1 && this.documentnoThreshold >= 0 && this.quotationnoThreshold >= 0 && this.returnnoThreshold >= 0) {
         if (callback) {
           callback();
         }
         return;
       }
 
-      //If documentnoSuffix === 0 || quotationnoSuffix === 0, it means that we have restarted documentNo prefix, so we block this method while we save the new documentNo in localStorage
-      if (documentnoSuffix === 0 || quotationnoSuffix === 0) {
+      //If documentnoSuffix === 0 || quotationnoSuffix === 0 || returnnoSuffix === 0, it means that we have restarted documentNo prefix, so we block this method while we save the new documentNo in localStorage
+      if (documentnoSuffix === 0 || quotationnoSuffix === 0 || returnnoSuffix === 0) {
         me.restartingDocNo = true;
       }
 
@@ -747,6 +748,9 @@
       if (quotationnoSuffix > this.quotationnoThreshold || quotationnoSuffix === 0) {
         this.quotationnoThreshold = quotationnoSuffix;
       }
+      if (returnnoSuffix > this.returnnoThreshold || returnnoSuffix === 0) {
+        this.returnnoThreshold = returnnoSuffix;
+      }
 
       var processDocumentSequenceList = function (documentSequenceList) {
 
@@ -761,6 +765,9 @@
             if (docSeq.get('quotationDocumentSequence') > me.quotationnoThreshold && quotationnoSuffix !== 0) {
               me.quotationnoThreshold = docSeq.get('quotationDocumentSequence');
             }
+            if (docSeq.get('returnDocumentSequence') > me.returnnoThreshold && returnnoSuffix !== 0) {
+              me.returnnoThreshold = docSeq.get('returnDocumentSequence');
+            }
           } else {
             // There is not a document sequence for the pos, create it
             docSeq = new OB.Model.DocumentSequence();
@@ -770,6 +777,7 @@
           // deprecation 27911 starts
           OB.MobileApp.model.set('documentsequence', me.getLastDocumentnoSuffixInOrderlist());
           OB.MobileApp.model.set('quotationDocumentSequence', me.getLastQuotationnoSuffixInOrderlist());
+          OB.MobileApp.model.set('returnDocumentSequence', me.getLastReturnnoSuffixInOrderlist());
           if (!me.isSeqNoReadyEventSent) {
             me.isSeqNoReadyEventSent = true;
             me.trigger('seqNoReady');
@@ -778,6 +786,7 @@
           // update the database
           docSeq.set('documentSequence', me.documentnoThreshold);
           docSeq.set('quotationDocumentSequence', me.quotationnoThreshold);
+          docSeq.set('returnDocumentSequence', me.returnnoThreshold);
           OB.Dal.saveInTransaction(tx, docSeq, function () {
             if (callback) {
               callback();
@@ -799,12 +808,17 @@
     /**
      * Updates the document sequence. This method should only be called when an order has been sent to the server
      * If the order is a quotation, only update the quotationno
+     * If the order is a return, only update the returnno
      */
-    updateDocumentSequenceWhenOrderSaved: function (documentnoSuffix, quotationnoSuffix, callback, tx) {
+    updateDocumentSequenceWhenOrderSaved: function (documentnoSuffix, quotationnoSuffix, returnnoSuffix, callback, tx) {
       if (quotationnoSuffix >= 0) {
         documentnoSuffix = -1;
+        returnnoSuffix = -1;
+      } else if (returnnoSuffix >= 0) {
+        documentnoSuffix = -1;
+        quotationnoSuffix = -1;
       }
-      this.saveDocumentSequence(documentnoSuffix, quotationnoSuffix, callback, tx);
+      this.saveDocumentSequence(documentnoSuffix, quotationnoSuffix, returnnoSuffix, callback, tx);
     },
 
     // get the first document number available
@@ -814,7 +828,7 @@
         var i = 0;
         while (lastSuffix === null && i <= OB.MobileApp.model.orderList.models.length - 1) {
           var order = OB.MobileApp.model.orderList.models[i];
-          if (!order.get('isPaid') && !order.get('isQuotation') && order.get('documentnoPrefix') === OB.MobileApp.model.get('terminal').docNoPrefix) {
+          if (!order.get('isPaid') && !order.get('isQuotation') && !order.get('isReturn') && order.get('documentnoPrefix') === OB.MobileApp.model.get('terminal').docNoPrefix) {
             lastSuffix = order.get('documentnoSuffix');
           }
           i++;
@@ -843,6 +857,24 @@
       }
       return lastSuffix;
     },
+    // get the first return number available
+    getLastReturnnoSuffixInOrderlist: function () {
+      var lastSuffix = null;
+      if (OB.MobileApp.model.orderList && OB.MobileApp.model.orderList.length > 0) {
+        var i = OB.MobileApp.model.orderList.models.length - 1;
+        while (lastSuffix === null && i >= 0) {
+          var order = OB.MobileApp.model.orderList.models[i];
+          if ((order.getOrderType() === 1 || order.get('gross') < 0) && order.get('returnnoPrefix') === OB.MobileApp.model.get('terminal').returnDocNoPrefix) {
+            lastSuffix = order.get('returnnoSuffix');
+          }
+          i--;
+        }
+      }
+      if (lastSuffix === null || lastSuffix < this.returnnoThreshold) {
+        lastSuffix = this.returnnoThreshold;
+      }
+      return lastSuffix;
+    },
 
     // call this method to get a new order document number
     getNextDocumentno: function () {
@@ -860,6 +892,14 @@
         documentNo: OB.MobileApp.model.get('terminal').quotationDocNoPrefix + '/' + OB.UTIL.padNumber(next, 7)
       };
     },
+    // call this method to get a new Return document number
+    getNextReturnno: function () {
+      var next = this.getLastReturnnoSuffixInOrderlist() + 1;
+      return {
+        documentnoSuffix: next,
+        documentNo: OB.MobileApp.model.get('terminal').returnDocNoPrefix + '/' + OB.UTIL.padNumber(next, 7)
+      };
+    },
 
     getPaymentName: function (key) {
       if (this.paymentnames[key] && this.paymentnames[key].payment && this.paymentnames[key].payment._identifier) {
diff -r 962eab45efce -r e20983d3cf8d web/org.openbravo.retail.posterminal/js/model/document-sequence.js
--- a/web/org.openbravo.retail.posterminal/js/model/document-sequence.js	Thu Mar 03 08:00:49 2016 -0600
+++ b/web/org.openbravo.retail.posterminal/js/model/document-sequence.js	Thu Mar 03 14:55:41 2016 +0530
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2012 Openbravo S.L.U.
+ * Copyright (C) 2012-2016 Openbravo S.L.U.
  * Licensed under the Openbravo Commercial License version 1.0
  * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
  * or in the legal folder of this module distribution.
@@ -16,22 +16,24 @@
     entityName: '',
     source: '',
     local: true,
-    properties: ['id', 'posSearchKey', 'documentSequence', 'quotationDocumentSequence'],
+    properties: ['id', 'posSearchKey', 'documentSequence', 'quotationDocumentSequence', 'returnDocumentSequence'],
     propertyMap: {
       'id': 'c_document_sequence_id',
       'posSearchKey': 'pos_search_key',
       'documentSequence': 'document_sequence',
-      'quotationDocumentSequence': 'quotation_document_sequence'
+      'quotationDocumentSequence': 'quotation_document_sequence',
+      'returnDocumentSequence': 'return_document_sequence'
     },
 
     defaults: {
       documentSequence: 0,
-      quotationDocumentSequence: 0
+      quotationDocumentSequence: 0,
+      returnDocumentSequence: 0
     },
 
-    createStatement: 'CREATE TABLE IF NOT EXISTS c_document_sequence (c_document_sequence_id TEXT PRIMARY KEY, pos_search_key TEXT NOT NULL UNIQUE, document_sequence NUMBER, quotation_document_sequence NUMBER)',
+    createStatement: 'CREATE TABLE IF NOT EXISTS c_document_sequence (c_document_sequence_id TEXT PRIMARY KEY, pos_search_key TEXT NOT NULL UNIQUE, document_sequence NUMBER, quotation_document_sequence NUMBER, return_document_sequence NUMBER)',
     dropStatement: 'DROP TABLE IF EXISTS c_document_sequence',
-    insertStatement: 'INSERT INTO c_document_sequence(c_document_sequence_id, pos_search_key, document_sequence, quotation_document_sequence) VALUES (?,?,?,?)'
+    insertStatement: 'INSERT INTO c_document_sequence(c_document_sequence_id, pos_search_key, document_sequence, quotation_document_sequence, return_document_sequence) VALUES (?,?,?,?,?)'
   });
 
   OB.Data.Registry.registerModel(DocumentSequence);
diff -r 962eab45efce -r e20983d3cf8d web/org.openbravo.retail.posterminal/js/model/order.js
--- a/web/org.openbravo.retail.posterminal/js/model/order.js	Thu Mar 03 08:00:49 2016 -0600
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js	Thu Mar 03 14:55:41 2016 +0530
@@ -347,8 +347,10 @@
         this.set('creationDate', OB.I18N.normalizeDate(attributes.creationDate));
         this.set('documentnoPrefix', attributes.documentnoPrefix);
         this.set('quotationnoPrefix', attributes.quotationnoPrefix);
+        this.set('returnnoPrefix', attributes.returnnoPrefix);
         this.set('documentnoSuffix', attributes.documentnoSuffix);
         this.set('quotationnoSuffix', attributes.quotationnoSuffix);
+        this.set('returnnoSuffix', attributes.returnnoSuffix);
         this.set('documentNo', attributes.documentNo);
         this.setUndo('InitializeAttr', attributes.undo);
         bpModel = new Backbone.Model(attributes.bp);
@@ -749,6 +751,21 @@
       }
     },
 
+    setReturnDocumentNo: function () {
+      if (OB.MobileApp.model.get('terminal').returnDocNoPrefix) {
+        var order = this;
+        if (order.get('returnnoPrefix') !== OB.MobileApp.model.get('terminal').returnDocNoPrefix) {
+          var nextReturnno = OB.MobileApp.model.getNextReturnno();
+          order.set('returnnoPrefix', OB.MobileApp.model.get('terminal').returnDocNoPrefix);
+          order.set('returnnoSuffix', nextReturnno.documentnoSuffix);
+          order.set('documentnoPrefix', -1);
+          order.set('documentnoSuffix', -1);
+          order.set('documentNo', nextReturnno.documentNo);
+          order.trigger('saveCurrent');
+        }
+      }
+    },
+
     getQty: function () {
       return this.get('qty');
     },
@@ -836,8 +853,10 @@
       this.set('creationDate', null);
       this.set('documentnoPrefix', -1);
       this.set('quotationnoPrefix', -1);
+      this.set('returnnoPrefix', -1);
       this.set('documentnoSuffix', -1);
       this.set('quotationnoSuffix', -1);
+      this.set('returnnoSuffix', -1);
       this.set('documentNo', '');
       this.set('undo', null);
       this.set('bp', null);
@@ -2419,6 +2438,8 @@
       this.set('documentnoSuffix', nextDocumentno.documentnoSuffix);
       this.set('quotationnoPrefix', -1);
       this.set('quotationnoSuffix', -1);
+      this.set('returnnoPrefix', -1);
+      this.set('returnnoSuffix', -1);
       this.set('documentNo', nextDocumentno.documentNo);
       this.set('posTerminal', OB.MobileApp.model.get('terminal').id);
       this.set('session', OB.MobileApp.model.get('session'));
diff -r 962eab45efce -r e20983d3cf8d web/org.openbravo.retail.posterminal/js/pointofsale/model/pointofsale-model.js
--- a/web/org.openbravo.retail.posterminal/js/pointofsale/model/pointofsale-model.js	Thu Mar 03 08:00:49 2016 -0600
+++ b/web/org.openbravo.retail.posterminal/js/pointofsale/model/pointofsale-model.js	Thu Mar 03 14:55:41 2016 +0530
@@ -60,7 +60,8 @@
 
       // Getting Max Document No, Quotation No from Unpaid orders
       var maxDocumentNo = 0,
-          maxQuotationNo = 0;
+          maxQuotationNo = 0,
+          maxReturnNo = 0;
       _.each(ordersNotPaid.models, function (order) {
         if (order) {
           if (order.get('documentnoSuffix') > maxDocumentNo) {
@@ -69,6 +70,9 @@
           if (order.get('quotationnoSuffix') > maxQuotationNo) {
             maxQuotationNo = order.get('quotationnoSuffix');
           }
+          if (order.get('returnnoSuffix') > maxReturnNo) {
+            maxReturnNo = order.get('returnnoSuffix');
+          }
         }
       });
 
@@ -79,6 +83,9 @@
       if (maxQuotationNo > 0 && OB.MobileApp.model.quotationnoThreshold < maxQuotationNo) {
         OB.MobileApp.model.quotationnoThreshold = maxQuotationNo;
       }
+      if (maxReturnNo > 0 && OB.MobileApp.model.returnnoThreshold < maxReturnNo) {
+        OB.MobileApp.model.returnnoThreshold = maxReturnNo;
+      }
 
       // Removing Orders which are created in other users session 
       var outOfSessionOrder = _.filter(ordersNotPaid.models, function (order) {
