Related to issue 30082: code review improvements
authorVíctor Martínez Romanos <victor.martinez@openbravo.com>
Fri, 12 Jun 2015 12:49:18 +0200
changeset 26910 ab5e14425861
parent 26909 99cc73c54bf0
child 26912 3ee971fcdd28
Related to issue 30082: code review improvements

The invoice's payment schedules and payment monitor is only updated when all the payment schedule details are paid.

This changeset covers the scenario where an order is partially paid. Before this change, the invoice's payment schedules and payment monitor were wrongly updated considering that the payment schedule was fully paid when any of its payment schedule details was paid. That asumption may be wrong in some scenarios, for example when the order is associated to one or more payment schedule details not yet paid (isinvoicepaid=N) and at least one already paid.
modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml	Wed Jun 10 13:09:56 2015 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml	Fri Jun 12 12:49:18 2015 +0200
@@ -934,11 +934,11 @@
 	      FROM fin_payment_schedule fps
 	      WHERE exists(select 1
 			   from fin_payment_scheduledetail fpsd
-		           where (fps.fin_payment_schedule_id = fpsd.fin_payment_schedule_order OR fps.fin_payment_schedule_id = fpsd.fin_payment_schedule_invoice)
-		           and isinvoicepaid='Y')
-		AND FIN_PAYMENT_SCHEDULE_ID = cur_paymentschedule.FIN_PAYMENT_SCHEDULE_ID;
+		           where fps.fin_payment_schedule_id = fpsd.fin_payment_schedule_invoice
+		           and fpsd.isinvoicepaid='N')
+              AND FIN_PAYMENT_SCHEDULE_ID = cur_paymentschedule.FIN_PAYMENT_SCHEDULE_ID;
 
-              IF (cur_finaccpaymentmethod.ExecutionType<>'A' AND v_count > 0) THEN
+              IF (cur_finaccpaymentmethod.ExecutionType<>'A' AND v_count = 0) THEN
                 UPDATE FIN_PAYMENT_SCHEDULE
                 SET PAIDAMT = PAIDAMT + COALESCE(cur_paymentschedule.OUTSTANDINGAMT,0),
                     OUTSTANDINGAMT = OUTSTANDINGAMT - COALESCE(cur_paymentschedule.OUTSTANDINGAMT, 0)