details:   https://code.openbravo.com/erp/devel/pi/rev/1ac215963112
changeset: 32629:1ac215963112
user:      Atul Gaware <atul.gaware <at> openbravo.com>
date:      Wed Sep 06 16:51:30 2017 +0530
summary:   Fixes issue 36753: Error in Payment Plan after execute a payment

** Use FIN_Utility updatePaymentAmounts method instead of private 
updatePaymentAmounts
method in FIN_ExecutePayment to avoid wrong updation of fin_payment_schedule
** Use FIN_Utility updateBusinessPartnerCredit
** Remove break statement
** Removed unused private updatePaymentAmounts method from FIN_ExecutePayment

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java
 |  50 +---------
 1 files changed, 2 insertions(+), 48 deletions(-)

diffs (70 lines):

diff -r a6d788e3208b -r 1ac215963112 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java
     Fri Sep 08 00:55:48 2017 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java
     Wed Sep 06 16:51:30 2017 +0530
@@ -210,11 +210,11 @@
                         return processTransactionError;
                       }
                     }
-                    updatePaymentAmounts(paymentRunPayment.getPayment());
+                    FIN_Utility.updatePaymentAmounts(psd);
                   }
                 }
-                break;
               }
+              
FIN_Utility.updateBusinessPartnerCredit(paymentRunPayment.getPayment());
             } finally {
               OBContext.restorePreviousMode();
             }
@@ -265,52 +265,6 @@
         constantParameters.put(parameter.getSearchKey(), 
parameter.getDefaultTextValue());
   }
 
-  private static void updatePaymentAmounts(FIN_Payment payment) {
-    for (FIN_PaymentDetail pDetail : payment.getFINPaymentDetailList()) {
-      for (FIN_PaymentScheduleDetail psd : 
pDetail.getFINPaymentScheduleDetailList()) {
-        if (psd.getInvoicePaymentSchedule() != null) {
-          BusinessPartner bPartner = 
psd.getInvoicePaymentSchedule().getInvoice()
-              .getBusinessPartner();
-          BigDecimal creditUsed = bPartner.getCreditUsed();
-          BigDecimal amountWithSign = 
psd.getInvoicePaymentSchedule().getInvoice()
-              .isSalesTransaction() ? psd.getAmount() : 
psd.getAmount().negate();
-          creditUsed = creditUsed.subtract(amountWithSign);
-          bPartner.setCreditUsed(creditUsed);
-          OBDal.getInstance().save(bPartner);
-          FIN_AddPayment.updatePaymentScheduleAmounts(pDetail, 
psd.getInvoicePaymentSchedule(),
-              psd.getAmount(), psd.getWriteoffAmount());
-        }
-        if (psd.getOrderPaymentSchedule() != null) {
-          FIN_AddPayment.updatePaymentScheduleAmounts(pDetail, 
psd.getOrderPaymentSchedule(),
-              psd.getAmount(), psd.getWriteoffAmount());
-        }
-        if (pDetail.isPrepayment() && psd.getOrderPaymentSchedule() == null
-            && psd.getInvoicePaymentSchedule() == null) {
-          // This PSD is credit
-          BusinessPartner bPartner = 
psd.getPaymentDetails().getFinPayment().getBusinessPartner();
-          BigDecimal creditUsed = bPartner.getCreditUsed();
-          BigDecimal amountWithSign = 
psd.getPaymentDetails().getFinPayment().isReceipt() ? psd
-              .getAmount() : psd.getAmount().negate();
-          creditUsed = creditUsed.subtract(amountWithSign);
-          bPartner.setCreditUsed(creditUsed);
-          OBDal.getInstance().save(bPartner);
-        }
-      }
-    }
-    // When credit is used (consumed) we compensate so_creditused as this 
amount is already
-    // included in the payment details. Credit consumed should not affect to 
so_creditused
-    if (payment.getGeneratedCredit().compareTo(BigDecimal.ZERO) == 0
-        && payment.getUsedCredit().compareTo(BigDecimal.ZERO) != 0) {
-      BusinessPartner bp = payment.getBusinessPartner();
-      if (payment.isReceipt()) {
-        bp.setCreditUsed(bp.getCreditUsed().add(payment.getUsedCredit()));
-      } else {
-        bp.setCreditUsed(bp.getCreditUsed().subtract(payment.getUsedCredit()));
-      }
-      OBDal.getInstance().save(bp);
-    }
-  }
-
   /**
    * It calls the Transaction Process for the given transaction and action.
    * 

------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to