Merged from Cancel and Replace branch
authorUnai Martirena <unai.martirena@openbravo.com>
Thu, 16 Jun 2016 12:31:12 +0200
changeset 29818 6f0db2e1df44
parent 29815 4933ec2c94ff (current diff)
parent 29817 d6fdf29f0260 (diff)
child 29820 1f31a135506f
Merged from Cancel and Replace branch
src-db/database/model/tables/C_ORDER.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/erpCommon/businessUtility/CancelAndReplaceUtils.java
--- a/src-db/database/model/tables/C_ORDER.xml	Fri Jun 10 09:44:44 2016 +0200
+++ b/src-db/database/model/tables/C_ORDER.xml	Thu Jun 16 12:31:12 2016 +0200
@@ -361,6 +361,10 @@
         <default><![CDATA[N]]></default>
         <onCreateDefault><![CDATA['N']]></onCreateDefault>
       </column>
+      <column name="REPLACEMENTORDER_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
       <foreign-key foreignTable="C_DOCTYPE" name="C_DOCTYPE_CORDER">
         <reference local="C_DOCTYPE_ID" foreign="C_DOCTYPE_ID"/>
       </foreign-key>
@@ -454,6 +458,9 @@
       <foreign-key foreignTable="C_ORDER" name="C_ORDER_REPLACEDORDER">
         <reference local="REPLACEDORDER_ID" foreign="C_ORDER_ID"/>
       </foreign-key>
+      <foreign-key foreignTable="C_ORDER" name="C_ORDER_REPLACEMENTORDER">
+        <reference local="REPLACEMENTORDER_ID" foreign="C_ORDER_ID"/>
+      </foreign-key>
       <foreign-key foreignTable="AD_USER" name="C_ORDER_SALESREP">
         <reference local="SALESREP_ID" foreign="AD_USER_ID"/>
       </foreign-key>
@@ -498,6 +505,9 @@
       <index name="C_ORDER_REPLACEDORDER_ID" unique="false">
         <index-column name="REPLACEDORDER_ID"/>
       </index>
+      <index name="C_ORDER_REPLACEMENTORDER_ID" unique="false">
+        <index-column name="REPLACEMENTORDER_ID"/>
+      </index>
       <index name="C_ORDER_UPDATED" unique="false">
         <index-column name="UPDATED"/>
       </index>
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Fri Jun 10 09:44:44 2016 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Thu Jun 16 12:31:12 2016 +0200
@@ -369965,6 +369965,42 @@
 <!--E59D4BB7F1C342619CB4131FE4888FFA-->  <ALLOWED_CROSS_ORG_LINK><![CDATA[N]]></ALLOWED_CROSS_ORG_LINK>
 <!--E59D4BB7F1C342619CB4131FE4888FFA--></AD_COLUMN>
 
+<!--E61022D568524DD78F02815F50092DB8--><AD_COLUMN>
+<!--E61022D568524DD78F02815F50092DB8-->  <AD_COLUMN_ID><![CDATA[E61022D568524DD78F02815F50092DB8]]></AD_COLUMN_ID>
+<!--E61022D568524DD78F02815F50092DB8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E61022D568524DD78F02815F50092DB8-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E61022D568524DD78F02815F50092DB8-->  <NAME><![CDATA[Replacementorder_ID]]></NAME>
+<!--E61022D568524DD78F02815F50092DB8-->  <DESCRIPTION><![CDATA[Link to the replacement order]]></DESCRIPTION>
+<!--E61022D568524DD78F02815F50092DB8-->  <HELP><![CDATA[Link to the replacement order]]></HELP>
+<!--E61022D568524DD78F02815F50092DB8-->  <COLUMNNAME><![CDATA[Replacementorder_ID]]></COLUMNNAME>
+<!--E61022D568524DD78F02815F50092DB8-->  <AD_TABLE_ID><![CDATA[259]]></AD_TABLE_ID>
+<!--E61022D568524DD78F02815F50092DB8-->  <AD_REFERENCE_ID><![CDATA[18]]></AD_REFERENCE_ID>
+<!--E61022D568524DD78F02815F50092DB8-->  <AD_REFERENCE_VALUE_ID><![CDATA[290]]></AD_REFERENCE_VALUE_ID>
+<!--E61022D568524DD78F02815F50092DB8-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--E61022D568524DD78F02815F50092DB8-->  <SEQNO><![CDATA[750]]></SEQNO>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--E61022D568524DD78F02815F50092DB8-->  <AD_ELEMENT_ID><![CDATA[06D885749834459BABA740AA25636ECA]]></AD_ELEMENT_ID>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--E61022D568524DD78F02815F50092DB8-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--E61022D568524DD78F02815F50092DB8-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--E61022D568524DD78F02815F50092DB8-->  <POSITION><![CDATA[103]]></POSITION>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--E61022D568524DD78F02815F50092DB8-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--E61022D568524DD78F02815F50092DB8-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--E61022D568524DD78F02815F50092DB8-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--E61022D568524DD78F02815F50092DB8--></AD_COLUMN>
+
 <!--E631C21ED303AC60E040007F01002676--><AD_COLUMN>
 <!--E631C21ED303AC60E040007F01002676-->  <AD_COLUMN_ID><![CDATA[E631C21ED303AC60E040007F01002676]]></AD_COLUMN_ID>
 <!--E631C21ED303AC60E040007F01002676-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_ELEMENT.xml	Fri Jun 10 09:44:44 2016 +0200
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml	Thu Jun 16 12:31:12 2016 +0200
@@ -21118,6 +21118,20 @@
 <!--06982089ED1442FAA0E2626D2228CF4E-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--06982089ED1442FAA0E2626D2228CF4E--></AD_ELEMENT>
 
+<!--06D885749834459BABA740AA25636ECA--><AD_ELEMENT>
+<!--06D885749834459BABA740AA25636ECA-->  <AD_ELEMENT_ID><![CDATA[06D885749834459BABA740AA25636ECA]]></AD_ELEMENT_ID>
+<!--06D885749834459BABA740AA25636ECA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--06D885749834459BABA740AA25636ECA-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--06D885749834459BABA740AA25636ECA-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--06D885749834459BABA740AA25636ECA-->  <COLUMNNAME><![CDATA[Replacementorder_ID]]></COLUMNNAME>
+<!--06D885749834459BABA740AA25636ECA-->  <NAME><![CDATA[Replacement Order]]></NAME>
+<!--06D885749834459BABA740AA25636ECA-->  <PRINTNAME><![CDATA[Replacement Order]]></PRINTNAME>
+<!--06D885749834459BABA740AA25636ECA-->  <DESCRIPTION><![CDATA[Link to the replacement order]]></DESCRIPTION>
+<!--06D885749834459BABA740AA25636ECA-->  <HELP><![CDATA[Link to the replacement order]]></HELP>
+<!--06D885749834459BABA740AA25636ECA-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--06D885749834459BABA740AA25636ECA-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--06D885749834459BABA740AA25636ECA--></AD_ELEMENT>
+
 <!--073EB11474B542B5AA579581C8741C53--><AD_ELEMENT>
 <!--073EB11474B542B5AA579581C8741C53-->  <AD_ELEMENT_ID><![CDATA[073EB11474B542B5AA579581C8741C53]]></AD_ELEMENT_ID>
 <!--073EB11474B542B5AA579581C8741C53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Fri Jun 10 09:44:44 2016 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Thu Jun 16 12:31:12 2016 +0200
@@ -232695,6 +232695,35 @@
 <!--70AEECD6D8A8479792ACAD28B2937C57-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--70AEECD6D8A8479792ACAD28B2937C57--></AD_FIELD>
 
+<!--70B30B77B3F347D6A4CCE368FF95426B--><AD_FIELD>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <AD_FIELD_ID><![CDATA[70B30B77B3F347D6A4CCE368FF95426B]]></AD_FIELD_ID>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <NAME><![CDATA[Replacement Order]]></NAME>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <DESCRIPTION><![CDATA[Link to the replacement order]]></DESCRIPTION>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <HELP><![CDATA[Link to the replacement order]]></HELP>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <AD_TAB_ID><![CDATA[186]]></AD_TAB_ID>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <AD_COLUMN_ID><![CDATA[E61022D568524DD78F02815F50092DB8]]></AD_COLUMN_ID>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <DISPLAYLOGIC><![CDATA[@Replacementorder_ID@!'']]></DISPLAYLOGIC>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISREADONLY><![CDATA[Y]]></ISREADONLY>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <SEQNO><![CDATA[135]]></SEQNO>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--70B30B77B3F347D6A4CCE368FF95426B-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--70B30B77B3F347D6A4CCE368FF95426B--></AD_FIELD>
+
 <!--70BC8DA302454124BFE119D7641B50D8--><AD_FIELD>
 <!--70BC8DA302454124BFE119D7641B50D8-->  <AD_FIELD_ID><![CDATA[70BC8DA302454124BFE119D7641B50D8]]></AD_FIELD_ID>
 <!--70BC8DA302454124BFE119D7641B50D8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Fri Jun 10 09:44:44 2016 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Thu Jun 16 12:31:12 2016 +0200
@@ -304,6 +304,7 @@
       // Close original order
       oldOrder.setDocumentStatus("CL");
       oldOrder.setDocumentAction("--");
+      oldOrder.setReplacementorder(newOrder);
       oldOrder.setCancelled(true);
       oldOrder.setProcessed(true);
       oldOrder.setProcessNow(false);
@@ -866,8 +867,10 @@
                 newPaymentSchedule.getPaidAmount()));
           }
 
-          finishOrderPayments(jsonorder, oldOrder, inverseOrder, paymentSchedule,
-              useOrderDocumentNoForRelatedDocs, triggersDisabled, replaceOrder);
+          if (paymentSchedule.getOutstandingAmount().compareTo(BigDecimal.ZERO) != 0) {
+            finishOrderPayments(jsonorder, oldOrder, inverseOrder, paymentSchedule,
+                useOrderDocumentNoForRelatedDocs, triggersDisabled, replaceOrder);
+          }
         }
 
       } else {
@@ -923,14 +926,10 @@
     newPayment = createPayment(newPayment, inverseOrder, paymentPaymentMethod, negativeAmount,
         paymentDocumentType, financialAccount, paymentDocumentNo);
 
-    // Create if needed a second payment for the partially paid
-    if (outstandingAmount.compareTo(BigDecimal.ZERO) != 0) {
-
-      // Duplicate payment with positive amount
-      newPayment = createPayment(newPayment, oldOrder, paymentPaymentMethod, outstandingAmount,
-          paymentDocumentType, financialAccount, paymentDocumentNo);
-      description += ": " + oldOrder.getDocumentNo() + "\n";
-    }
+    // Duplicate payment with positive amount
+    newPayment = createPayment(newPayment, oldOrder, paymentPaymentMethod, outstandingAmount,
+        paymentDocumentType, financialAccount, paymentDocumentNo);
+    description += ": " + oldOrder.getDocumentNo() + "\n";
 
     // Set amount and used credit to zero
     newPayment.setAmount(BigDecimal.ZERO);
@@ -948,6 +947,7 @@
     if (triggersDisabled && replaceOrder) {
       TriggerHandler.getInstance().disable();
     }
+
   }
 
   protected static FIN_Payment createPayment(FIN_Payment payment, Order order,