Related to issue 30115: code review improvements
authorVíctor Martínez Romanos <victor.martinez@openbravo.com>
Fri, 12 Jun 2015 12:05:42 +0200
changeset 26996 ebc2affd351e
parent 26995 dc78e10a61a0
child 26997 5612ad11863b
Related to issue 30115: code review improvements
Reduced useless query complexity to update outstanding amount.
It's only necessary to check fin_payment_detail_id is null (not associated payment) or isinvoicepaid='N' (associated payment but in a non paid yet status)
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 10:52:18 2015 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml	Fri Jun 12 12:05:42 2015 +0200
@@ -919,13 +919,7 @@
                       OUTSTANDINGAMT = (SELECT COALESCE(sum(amount), 0)
                                         FROM fin_payment_scheduledetail
                                         WHERE fin_payment_schedule_order=cur_PaymentScheduleOrder.FIN_PAYMENT_SCHEDULE_ORDER AND
-                                              (fin_payment_detail_id is null OR
-                                       exists (SELECT 1
-                                               FROM fin_payment, fin_payment_detail
-                                               WHERE fin_payment.fin_payment_id = fin_payment_detail.fin_payment_id
-                                                      and fin_payment.processed='Y' 
-                                                      and fin_payment_scheduledetail.isinvoicepaid<>'Y'
-                                                      and fin_payment_detail.fin_payment_detail_id = fin_payment_scheduledetail.fin_payment_detail_id)))
+                                        (fin_payment_detail_id is null OR isinvoicepaid='N'))
 
                   WHERE FIN_PAYMENT_SCHEDULE_ID = cur_PaymentScheduleOrder.FIN_PAYMENT_SCHEDULE_ORDER;
                 END IF;