details:   https://code.openbravo.com/erp/devel/main/rev/5da1fa7fdb5c
changeset: 30399:5da1fa7fdb5c
user:      RM packaging bot <staff.rm <at> openbravo.com>
date:      Wed Oct 05 17:32:05 2016 +0000
summary:   CI: merge back from main

details:   https://code.openbravo.com/erp/devel/main/rev/dc0e10831b4e
changeset: 30400:dc0e10831b4e
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Mon Oct 10 11:09:34 2016 +0200
summary:   Related to issue 34038: Code review improvements

Remove FINPaymentEventHandler event handler and include the logic in existing 
FIN_PaymentEventListener event handler.
Remove unneeded payment parameter in setDocumentNoToPayment method.
Call payment.isProcessed() instead of event.getCurrentState(processedProperty).

details:   https://code.openbravo.com/erp/devel/main/rev/bfe0fd55340f
changeset: 30401:bfe0fd55340f
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Tue Oct 11 14:42:30 2016 +0200
summary:   Related to issue 34068: Fix stock valuation

Fix stock valuation in case we are updating valuation but stock was not updated 
yet.
Only in case we are updating stock and it is updated to zero, valuation will be 
updated to zero too.

details:   https://code.openbravo.com/erp/devel/main/rev/11fdd66992d4
changeset: 30402:11fdd66992d4
user:      RM packaging bot <staff.rm <at> openbravo.com>
date:      Wed Oct 12 20:39:04 2016 +0200
summary:   Merge back from main

details:   https://code.openbravo.com/erp/devel/main/rev/9b5b1cc15f9c
changeset: 30403:9b5b1cc15f9c
user:      RM packaging bot <staff.rm <at> openbravo.com>
date:      Thu Oct 13 09:13:55 2016 +0000
summary:   CI: update AD_MODULE to version 30402

diffstat:

 .hgsigs                                                                        
                           |    1 +
 .hgtags                                                                        
                           |    1 +
 modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE.xml  
                           |    2 +-
 
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                  |    4 +-
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FINPaymentEventHandler.java
   |  118 ----------
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FIN_PaymentEventListener.java
 |   68 ++++-
 
modules/org.openbravo.apachejdbcconnectionpool/src-db/database/sourcedata/AD_MODULE.xml
                   |    2 +-
 
modules/org.openbravo.apachejdbcconnectionpool/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
        |    2 +-
 modules/org.openbravo.base.weld/src-db/database/sourcedata/AD_MODULE.xml       
                           |    2 +-
 
modules/org.openbravo.base.weld/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                       |    2 +-
 
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MODULE.xml
                         |    2 +-
 
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
              |    8 +-
 
modules/org.openbravo.client.htmlwidget/src-db/database/sourcedata/AD_MODULE.xml
                          |    2 +-
 
modules/org.openbravo.client.htmlwidget/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
               |    2 +-
 modules/org.openbravo.client.kernel/src-db/database/sourcedata/AD_MODULE.xml   
                           |    2 +-
 
modules/org.openbravo.client.kernel/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                   |    6 +-
 modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_MODULE.xml     
                           |    2 +-
 
modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                     |    4 +-
 
modules/org.openbravo.client.querylist/src-db/database/sourcedata/AD_MODULE.xml 
                          |    2 +-
 
modules/org.openbravo.client.querylist/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                |    2 +-
 modules/org.openbravo.client.widgets/src-db/database/sourcedata/AD_MODULE.xml  
                           |    2 +-
 
modules/org.openbravo.client.widgets/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                  |    2 +-
 
modules/org.openbravo.financial.paymentreport/src-db/database/sourcedata/AD_MODULE.xml
                    |    2 +-
 
modules/org.openbravo.financial.paymentreport/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
         |    2 +-
 
modules/org.openbravo.reports.ordersawaitingdelivery/src-db/database/sourcedata/AD_MODULE.xml
             |    2 +-
 
modules/org.openbravo.reports.ordersawaitingdelivery/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
  |    2 +-
 
modules/org.openbravo.service.datasource/src-db/database/sourcedata/AD_MODULE.xml
                         |    2 +-
 
modules/org.openbravo.service.datasource/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
              |   10 +-
 
modules/org.openbravo.service.integration.google/src-db/database/sourcedata/AD_MODULE.xml
                 |    2 +-
 
modules/org.openbravo.service.integration.google/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
      |    4 +-
 
modules/org.openbravo.service.integration.openid/src-db/database/sourcedata/AD_MODULE.xml
                 |    2 +-
 
modules/org.openbravo.service.integration.openid/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
      |    2 +-
 modules/org.openbravo.service.json/src-db/database/sourcedata/AD_MODULE.xml    
                           |    2 +-
 
modules/org.openbravo.service.json/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                    |    2 +-
 
modules/org.openbravo.userinterface.selector/src-db/database/sourcedata/AD_MODULE.xml
                     |    2 +-
 
modules/org.openbravo.userinterface.selector/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
          |   12 +-
 
modules/org.openbravo.userinterface.skin.250to300Comp/src-db/database/sourcedata/AD_MODULE.xml
            |    2 +-
 
modules/org.openbravo.userinterface.skin.250to300Comp/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
 |    2 +-
 
modules/org.openbravo.userinterface.smartclient/src-db/database/sourcedata/AD_MODULE.xml
                  |    2 +-
 
modules/org.openbravo.userinterface.smartclient/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
       |    6 +-
 
modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_MODULE.xml
                        |    2 +-
 
modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
             |    2 +-
 modules/org.openbravo.v3.datasets/src-db/database/sourcedata/AD_MODULE.xml     
                           |    2 +-
 
modules/org.openbravo.v3.datasets/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                     |    6 +-
 modules/org.openbravo.v3.framework/src-db/database/sourcedata/AD_MODULE.xml    
                           |    2 +-
 
modules/org.openbravo.v3.framework/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
                    |   24 +-
 modules/org.openbravo.v3/src-db/database/sourcedata/AD_MODULE.xml              
                           |    2 +-
 modules/org.openbravo.v3/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml   
                           |   22 +-
 src-db/database/model/functions/M_UPDATE_STOCK_VALUATION.xml                   
                           |    7 +-
 src-db/database/sourcedata/AD_MODULE.xml                                       
                           |    2 +-
 50 files changed, 152 insertions(+), 217 deletions(-)

diffs (truncated from 1208 to 300 lines):

diff -r 9f948cce366c -r 9b5b1cc15f9c .hgsigs
--- a/.hgsigs   Wed Oct 05 17:17:43 2016 +0000
+++ b/.hgsigs   Thu Oct 13 09:13:55 2016 +0000
@@ -200,3 +200,4 @@
 c9da212632eaa8b5ad282ea755200a6761da6fa9 0 
iEYEABECAAYFAlftOagACgkQCX/oGf+2qkMyVgCfXQS09IJiOH63CblJE5zX6Qn3TDQAoPZnadaVKBEfROW6Ma1feqUrUgY/
 159bac1903e52d4f6785d5e53405ae988c273975 0 
iEYEABECAAYFAlejLbgACgkQCX/oGf+2qkOIMQCcDP51SEWDiDNBGTaEShgrqwhm7xYAoO/e+AXZ3cBSAhUb8CmIpJ0Rls82
 b91eab932a2640f7395e9c1b7d237c08303d0788 0 
iEYEABECAAYFAlfGHnMACgkQCX/oGf+2qkNXHQCgysf6qFN75kW873qTx3i0S9a2qjAAoI0R/AZCW4a6RPrNiFfjaWsOE3+v
+b79e30a5b3532f45101cedce0f3bb6b0a86b5780 0 
iEYEABECAAYFAlfz21YACgkQCX/oGf+2qkMqZgCgodjBPp4aS6GrpBTpumtr8DsFNAYAmwS3mdHHNYX8g8y4yIwjMDzmQG+o
diff -r 9f948cce366c -r 9b5b1cc15f9c .hgtags
--- a/.hgtags   Wed Oct 05 17:17:43 2016 +0000
+++ b/.hgtags   Thu Oct 13 09:13:55 2016 +0000
@@ -211,3 +211,4 @@
 6db3d7641170254dbd658eb774e36b092c68dd04 3.0PR16Q2.3
 ec10d529b9bbe8caa83f2ea72b29b94bd3473cae 3.0PR16Q3
 d0dee6596f281e29afcd159544992498896e93ff 3.0PR16Q3.1
+f252db9dde915c15574e3d5fa505bd1154e39c74 3.0PR16Q3.2
diff -r 9f948cce366c -r 9b5b1cc15f9c 
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE.xml
--- 
a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE.xml 
    Wed Oct 05 17:17:43 2016 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE.xml 
    Thu Oct 13 09:13:55 2016 +0000
@@ -6,7 +6,7 @@
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <NAME><![CDATA[Advanced Payables and 
Receivables Mngmt]]></NAME>
-<!--A918E3331C404B889D69AA9BFAFB23AC-->  
<VERSION><![CDATA[3.0.30377]]></VERSION>
+<!--A918E3331C404B889D69AA9BFAFB23AC-->  
<VERSION><![CDATA[3.0.30402]]></VERSION>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <DESCRIPTION><![CDATA[Managing your 
finances with an ERP does not have to be difficult. Enjoy a radically improved 
user experience that combines the power of an enterprise grade financial 
application with the simplicity and ease of a web 2.0 personal accounting 
service.]]></DESCRIPTION>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <HELP><![CDATA[Advanced Payables and 
Receivables Management simplifies and automates the business processes around 
the management of financial accounts, from the receipt and issue of payment, to 
the reconciliation of those events with bank statements.
 If you would like to help shape this module you are welcome to take part in 
the forum discussions or register feature requests or issues in the 
corresponding (Forum and Bug Tracking) sections in the Advanced Payables and 
Receivable project in the OB Forge.]]></HELP>
diff -r 9f948cce366c -r 9b5b1cc15f9c 
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
--- 
a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
  Wed Oct 05 17:17:43 2016 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
  Thu Oct 13 09:13:55 2016 +0000
@@ -7,7 +7,7 @@
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  
<AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  
<AD_DEPENDENT_MODULE_ID><![CDATA[5EB4F15C80684ACA904756BDC12ADBE5]]></AD_DEPENDENT_MODULE_ID>
-<!--89326AE95DAD449D85DFAB2C5B1C6683-->  
<STARTVERSION><![CDATA[2.1.30377]]></STARTVERSION>
+<!--89326AE95DAD449D85DFAB2C5B1C6683-->  
<STARTVERSION><![CDATA[2.1.30402]]></STARTVERSION>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <DEPENDANT_MODULE_NAME><![CDATA[User 
Interface Selector]]></DEPENDANT_MODULE_NAME>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  
<DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
@@ -21,7 +21,7 @@
 <!--B97FC854C6DD41E692161585645A900F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--B97FC854C6DD41E692161585645A900F-->  
<AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--B97FC854C6DD41E692161585645A900F-->  
<AD_DEPENDENT_MODULE_ID><![CDATA[0]]></AD_DEPENDENT_MODULE_ID>
-<!--B97FC854C6DD41E692161585645A900F-->  
<STARTVERSION><![CDATA[3.0.30377]]></STARTVERSION>
+<!--B97FC854C6DD41E692161585645A900F-->  
<STARTVERSION><![CDATA[3.0.30402]]></STARTVERSION>
 <!--B97FC854C6DD41E692161585645A900F-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--B97FC854C6DD41E692161585645A900F-->  
<DEPENDANT_MODULE_NAME><![CDATA[core]]></DEPENDANT_MODULE_NAME>
 <!--B97FC854C6DD41E692161585645A900F-->  
<DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
diff -r 9f948cce366c -r 9b5b1cc15f9c 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FINPaymentEventHandler.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FINPaymentEventHandler.java
   Wed Oct 05 17:17:43 2016 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
-/*
- *************************************************************************
- * The contents of this file are subject to the Openbravo  Public  License
- * Version  1.0  (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):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.event;
-
-import java.math.BigDecimal;
-
-import javax.enterprise.event.Observes;
-
-import org.apache.log4j.Logger;
-import org.openbravo.base.model.Entity;
-import org.openbravo.base.model.ModelProvider;
-import org.openbravo.base.model.Property;
-import org.openbravo.client.kernel.event.EntityDeleteEvent;
-import org.openbravo.client.kernel.event.EntityNewEvent;
-import org.openbravo.client.kernel.event.EntityPersistenceEvent;
-import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
-import org.openbravo.client.kernel.event.EntityUpdateEvent;
-import org.openbravo.erpCommon.businessUtility.CancelAndReplaceUtils;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-
-public class FINPaymentEventHandler extends EntityPersistenceEventObserver {
-  private static Entity[] entities = { ModelProvider.getInstance().getEntity(
-      FIN_Payment.ENTITY_NAME) };
-  protected Logger logger = Logger.getLogger(this.getClass());
-
-  @Override
-  protected Entity[] getObservedEntities() {
-    return entities;
-  }
-
-  public void onUpdate(@Observes
-  EntityUpdateEvent event) {
-    if (!isValidEvent(event)) {
-      return;
-    }
-    FIN_Payment payment = (FIN_Payment) event.getTargetInstance();
-    final Entity paymentEntity = 
ModelProvider.getInstance().getEntity(FIN_Payment.ENTITY_NAME);
-    final Property paymentAmountProperty = 
paymentEntity.getProperty(FIN_Payment.PROPERTY_AMOUNT);
-    BigDecimal oldPaymentAmount = (BigDecimal) 
event.getPreviousState(paymentAmountProperty);
-    String documentNo = payment.getDocumentNo();
-    int documentNoLength = payment.getDocumentNo().length();
-    if (payment.getAmount().compareTo(BigDecimal.ZERO) == 0) {
-      // Payment has no already an *Z* at the end of the document number
-      if (!CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.equals(documentNo
-          .substring(documentNoLength - 3))) {
-        String newDocumentNo = documentNo + 
CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX;
-        setDocumentNoToPayment(payment, event, newDocumentNo);
-      }
-    } else if (oldPaymentAmount.compareTo(BigDecimal.ZERO) == 0) {
-      if (CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.equals(documentNo
-          .substring(documentNoLength - 3))) {
-        String newDocumentNo = documentNo.substring(0, documentNoLength - 3);
-        setDocumentNoToPayment(payment, event, newDocumentNo);
-      }
-    }
-  }
-
-  public void onSave(@Observes
-  EntityNewEvent event) {
-    if (!isValidEvent(event)) {
-      return;
-    }
-    FIN_Payment payment = (FIN_Payment) event.getTargetInstance();
-    final Entity paymentEntity = 
ModelProvider.getInstance().getEntity(FIN_Payment.ENTITY_NAME);
-    final Property processedProperty = 
paymentEntity.getProperty(FIN_Payment.PROPERTY_PROCESSED);
-    if (payment.getAmount().compareTo(BigDecimal.ZERO) == 0) {
-      String newDocumentNo = payment.getDocumentNo();
-      boolean processed = false;
-      Object oProcessed = (processedProperty == null ? false : event
-          .getCurrentState(processedProperty));
-      if (oProcessed instanceof String) {
-        processed = "Y".equals(oProcessed.toString());
-      } else if (oProcessed instanceof Boolean) {
-        processed = (Boolean) oProcessed;
-      }
-      if (newDocumentNo.startsWith("<") && newDocumentNo.endsWith(">") && 
!processed) {
-        // Remove "<" and ">" characters from documentNo if payment is not 
processed
-        newDocumentNo = newDocumentNo.substring(1, newDocumentNo.length() - 1);
-      }
-      newDocumentNo = newDocumentNo + CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX;
-      setDocumentNoToPayment(payment, event, newDocumentNo);
-    }
-  }
-
-  public void onDelete(@Observes
-  EntityDeleteEvent event) {
-    if (!isValidEvent(event)) {
-      return;
-    }
-  }
-
-  private void setDocumentNoToPayment(FIN_Payment payment, 
EntityPersistenceEvent event,
-      String newDocumentNo) {
-    String truncatedDocumentNo = (newDocumentNo.length() > 30) ? 
newDocumentNo.substring(0, 30)
-        : newDocumentNo.toString();
-    final Entity paymentEntity = 
ModelProvider.getInstance().getEntity(FIN_Payment.ENTITY_NAME);
-    final Property paymentDocumentNoProperty = paymentEntity
-        .getProperty(FIN_Payment.PROPERTY_DOCUMENTNO);
-    event.setCurrentState(paymentDocumentNoProperty, truncatedDocumentNo);
-  }
-}
\ No newline at end of file
diff -r 9f948cce366c -r 9b5b1cc15f9c 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FIN_PaymentEventListener.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FIN_PaymentEventListener.java
 Wed Oct 05 17:17:43 2016 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FIN_PaymentEventListener.java
 Thu Oct 13 09:13:55 2016 +0000
@@ -11,13 +11,14 @@
  * 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-2015 Openbravo SLU
+ * All portions are Copyright (C) 2012-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
  */
 package org.openbravo.advpaymentmngt.event;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 import javax.enterprise.event.Observes;
@@ -30,11 +31,14 @@
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
 import org.openbravo.client.kernel.event.EntityDeleteEvent;
+import org.openbravo.client.kernel.event.EntityNewEvent;
+import org.openbravo.client.kernel.event.EntityPersistenceEvent;
 import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
 import org.openbravo.client.kernel.event.EntityUpdateEvent;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.businessUtility.CancelAndReplaceUtils;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
@@ -50,12 +54,53 @@
     return entities;
   }
 
+  public void onSave(@Observes EntityNewEvent event) {
+    if (!isValidEvent(event)) {
+      return;
+    }
+    FIN_Payment payment = (FIN_Payment) event.getTargetInstance();
+    if (payment.getAmount().compareTo(BigDecimal.ZERO) == 0) {
+      String newDocumentNo = payment.getDocumentNo();
+      if (newDocumentNo.startsWith("<") && newDocumentNo.endsWith(">") && 
!payment.isProcessed()) {
+        // Remove "<" and ">" characters from documentNo if payment is not 
processed
+        newDocumentNo = newDocumentNo.substring(1, newDocumentNo.length() - 1);
+      }
+      newDocumentNo = newDocumentNo + CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX;
+      setDocumentNoToPayment(event, newDocumentNo);
+    }
+  }
+
   public void onUpdate(@Observes EntityUpdateEvent event) {
     if (!isValidEvent(event)) {
       return;
     }
 
-    manageAPRMPendingPaymentFromInvoiceRecord(event);
+    final FIN_Payment payment = (FIN_Payment) event.getTargetInstance();
+    final Entity paymentEntity = 
ModelProvider.getInstance().getEntity(FIN_Payment.ENTITY_NAME);
+    final Property paymentAmountProperty = 
paymentEntity.getProperty(FIN_Payment.PROPERTY_AMOUNT);
+    BigDecimal oldPaymentAmount = (BigDecimal) 
event.getPreviousState(paymentAmountProperty);
+    final Property paymentStatusProperty = 
paymentEntity.getProperty(FIN_Payment.PROPERTY_STATUS);
+    final String currentPaymentStatus = (String) 
event.getCurrentState(paymentStatusProperty);
+    final String oldPaymentStatus = (String) 
event.getPreviousState(paymentStatusProperty);
+
+    String documentNo = payment.getDocumentNo();
+    int documentNoLength = payment.getDocumentNo().length();
+    if (payment.getAmount().compareTo(BigDecimal.ZERO) == 0) {
+      // Payment has no already an *Z* at the end of the document number
+      if (!CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.equals(documentNo
+          .substring(documentNoLength - 3))) {
+        String newDocumentNo = documentNo + 
CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX;
+        setDocumentNoToPayment(event, newDocumentNo);
+      }
+    } else if (oldPaymentAmount.compareTo(BigDecimal.ZERO) == 0) {
+      if (CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.equals(documentNo
+          .substring(documentNoLength - 3))) {
+        String newDocumentNo = documentNo.substring(0, documentNoLength - 3);
+        setDocumentNoToPayment(event, newDocumentNo);
+      }
+    }
+
+    manageAPRMPendingPaymentFromInvoiceRecord(payment, currentPaymentStatus, 
oldPaymentStatus);
   }
 
   public void onDelete(@Observes EntityDeleteEvent event) {
@@ -88,18 +133,12 @@
    * Returns the number of records updated or deleted (0 or 1)
    * 
    */
-  private int manageAPRMPendingPaymentFromInvoiceRecord(final 
EntityUpdateEvent event) {
+  private int manageAPRMPendingPaymentFromInvoiceRecord(FIN_Payment payment,
+      String currentPaymentStatus, String oldPaymentStatus) {
     try {
       OBContext.setAdminMode(true);
-
       int rowCount = 0;
 
-      final FIN_Payment payment = (FIN_Payment) event.getTargetInstance();
-      final Entity paymentEntity = 
ModelProvider.getInstance().getEntity(FIN_Payment.ENTITY_NAME);
-      final Property paymentStatusProperty = 
paymentEntity.getProperty(FIN_Payment.PROPERTY_STATUS);
-      final String currentPaymentStatus = (String) 
event.getCurrentState(paymentStatusProperty);
-      final String oldPaymentStatus = (String) 
event.getPreviousState(paymentStatusProperty);
-
       if (StringUtils.equals("RPAE", currentPaymentStatus)) {
         final PaymentExecutionProcess executionProcess = new 
AdvPaymentMngtDao()
             .getExecutionProcess(payment);
@@ -165,4 +204,13 @@
     rowCount = updateQry.executeUpdate();
     return rowCount;
   }
+
+  private void setDocumentNoToPayment(EntityPersistenceEvent event, String 
newDocumentNo) {
+    String truncatedDocumentNo = (newDocumentNo.length() > 30) ? 
newDocumentNo.substring(0, 30)
+        : newDocumentNo.toString();
+    final Entity paymentEntity = 
ModelProvider.getInstance().getEntity(FIN_Payment.ENTITY_NAME);
+    final Property paymentDocumentNoProperty = paymentEntity
+        .getProperty(FIN_Payment.PROPERTY_DOCUMENTNO);
+    event.setCurrentState(paymentDocumentNoProperty, truncatedDocumentNo);
+  }
 }
diff -r 9f948cce366c -r 9b5b1cc15f9c 
modules/org.openbravo.apachejdbcconnectionpool/src-db/database/sourcedata/AD_MODULE.xml
--- 
a/modules/org.openbravo.apachejdbcconnectionpool/src-db/database/sourcedata/AD_MODULE.xml
   Wed Oct 05 17:17:43 2016 +0000
+++ 
b/modules/org.openbravo.apachejdbcconnectionpool/src-db/database/sourcedata/AD_MODULE.xml
   Thu Oct 13 09:13:55 2016 +0000
@@ -6,7 +6,7 @@

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to