Fixes issue 30007: Payment schedule amount incorrectly calculated.
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Thu, 28 May 2015 12:58:25 +0200
changeset 26824 aed0c66779e9
parent 26823 1c6069a0eafa
child 26825 4f48ce65dacf
Fixes issue 30007: Payment schedule amount incorrectly calculated.

Payment schedule amount incorrectly calculated when adding a payment from reconcile window to a sales order.
FIN_TransactionProcess and PaidStatusEventHandler have been changed in order to set invoicepaid=true only when FIN_PaymentScheduleDetail has a related InvoicePaymentSchedule.
FIN_PaymentProcess.java has also been changed, in order to check invoicePaidAmounts only if FIN_PaymentScheduleDetail has a related InvoicePaymentSchedule.
In case of a payment to a order without an invoice, updatePaymentAmounts will be called only once.
Name of preference in UpdatePaymentPlan modulescript has been update to run it again and fix wrong data created by the issue.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentPlanData.class
src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan_data.xsql
src/org/openbravo/event/PaidStatusEventHandler.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu May 28 16:19:09 2015 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu May 28 12:58:25 2015 +0200
@@ -392,7 +392,8 @@
                     .invoicePaymentStatus(payment)));
                 paymentScheduleDetail.setInvoicePaid(false);
                 // Payment = 0 when the payment is generated by a invoice that consume credit
-                if (invoicePaidAmounts
+                if ((invoicePaidAmounts && paymentScheduleDetail.getInvoicePaymentSchedule() != null)
+                    || (paymentScheduleDetail.getOrderPaymentSchedule() != null)
                     || (payment.getAmount().compareTo(new BigDecimal("0.00")) == 0)) {
                   if (paymentScheduleDetail.getInvoicePaymentSchedule() != null) {
                     // BP SO_CreditUsed
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Thu May 28 16:19:09 2015 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Thu May 28 12:58:25 2015 +0200
@@ -137,7 +137,8 @@
             for (FIN_PaymentScheduleDetail psd : pd.getFINPaymentScheduleDetailList()) {
               invoicePaidold = psd.isInvoicePaid();
               if (!invoicePaidold) {
-                if ((FIN_Utility.invoicePaymentStatus(payment).equals(payment.getStatus()))) {
+                if (FIN_Utility.invoicePaymentStatus(payment).equals(payment.getStatus())
+                    && psd.getInvoicePaymentSchedule() != null) {
                   psd.setInvoicePaid(true);
                 }
                 if (psd.isInvoicePaid()) {
Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/UpdatePaymentPlanData.class has changed
--- a/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan_data.xsql	Thu May 28 16:19:09 2015 +0200
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdatePaymentPlan_data.xsql	Thu May 28 12:58:25 2015 +0200
@@ -54,7 +54,7 @@
         SELECT count(*) as exist
         FROM DUAL
         WHERE EXISTS (SELECT 1 FROM ad_preference
-                      WHERE attribute = 'PaymentPlanUpdatedV2')
+                      WHERE attribute = 'PaymentPlanUpdatedV3')
       ]]>
     </Sql>
   </SqlMethod>
@@ -66,7 +66,7 @@
            ad_preference_id, ad_client_id, ad_org_id, isactive,
            createdby, created, updatedby, updated,attribute
            ) VALUES (
-           get_uuid(), '0', '0', 'Y', '0', NOW(), '0', NOW(),'PaymentPlanUpdatedV2')
+           get_uuid(), '0', '0', 'Y', '0', NOW(), '0', NOW(),'PaymentPlanUpdatedV3')
          ]]>
         </Sql>
    </SqlMethod>
--- a/src/org/openbravo/event/PaidStatusEventHandler.java	Thu May 28 16:19:09 2015 +0200
+++ b/src/org/openbravo/event/PaidStatusEventHandler.java	Thu May 28 12:58:25 2015 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2014 Openbravo SLU
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -72,7 +72,8 @@
             for (FIN_PaymentScheduleDetail psd : pd.getFINPaymentScheduleDetailList()) {
               invoicePaidold = psd.isInvoicePaid();
               if (!invoicePaidold) {
-                if (newStatus.equals(transaction.getFinPayment().getStatus())) {
+                if (newStatus.equals(transaction.getFinPayment().getStatus())
+                    && psd.getInvoicePaymentSchedule() != null) {
                   psd.setInvoicePaid(true);
                 }
                 if (psd.isInvoicePaid()) {