details:   https://code.openbravo.com/erp/devel/pi/rev/6ae94a6a873d
changeset: 30493:6ae94a6a873d
user:      Asier Martirena <asier.martirena <at> openbravo.com>
date:      Tue Oct 18 11:45:46 2016 +0200
summary:   Fixed issue 34207: The sequence to create payments docNo was not 
correctly updated

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FIN_PaymentEventListener.java
 |  37 +++++----
 1 files changed, 20 insertions(+), 17 deletions(-)

diffs (55 lines):

diff -r 796c6f172597 -r 6ae94a6a873d 
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
 Tue Oct 18 08:36:30 2016 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/event/FIN_PaymentEventListener.java
 Tue Oct 18 11:45:46 2016 +0200
@@ -59,12 +59,8 @@
       return;
     }
     FIN_Payment payment = (FIN_Payment) event.getTargetInstance();
-    if (payment.getAmount().compareTo(BigDecimal.ZERO) == 0) {
+    if (payment.isProcessed() && 
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);
     }
@@ -85,18 +81,25 @@
 
     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);
+    if (payment.isProcessed()) {
+      if (payment.getAmount().compareTo(BigDecimal.ZERO) == 0) {
+        // Payment has no already an *Z* at the end of the document number
+        if (documentNo.length() < 
CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.length()
+            || !CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.equals(documentNo
+                .substring(documentNoLength - 
CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.length()))) {
+          String newDocumentNo = documentNo + 
CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX;
+          setDocumentNoToPayment(event, newDocumentNo);
+        }
+      } else if (oldPaymentAmount.compareTo(BigDecimal.ZERO) == 0) {
+        // The payment has already the *Z* at the end of the document number 
and is not a payment of
+        // 0
+        if (documentNo.length() >= 
CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.length()
+            && CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.equals(documentNo
+                .substring(documentNoLength - 
CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.length()))) {
+          String newDocumentNo = documentNo.substring(0, documentNoLength
+              - CancelAndReplaceUtils.ZERO_PAYMENT_SUFIX.length());
+          setDocumentNoToPayment(event, newDocumentNo);
+        }
       }
     }
 

------------------------------------------------------------------------------
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