details: https://code.openbravo.com/erp/devel/pi/rev/209da9cda816 changeset: 26907:209da9cda816 user: Jorge Garcia <jorge.garcia <at> openbravo.com> date: Wed Jun 10 10:52:18 2015 +0200 summary: Fixed issue 29972: Outstanding amount of sales order payment plan is not updated
The problem was that the outstanding amount of sales order payment plan is not updated when payment method is set as automatic receipt. Before the commit which introduces this regression, the function checked the status of the payment. With the changes, the function checks if the payment schedule detail is paid. The problem was in the update of the payment plan of the sales order, specifically in WHERE clause for outstanding amount. Now, the where clause works as expected, and the outstanding amount is updated properly. details: https://code.openbravo.com/erp/devel/pi/rev/70a9d6732cc5 changeset: 26908:70a9d6732cc5 user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Fri Jun 12 12:05:42 2015 +0200 summary: Related to issue 29972: 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) details: https://code.openbravo.com/erp/devel/pi/rev/99cc73c54bf0 changeset: 26909:99cc73c54bf0 user: Jorge Garcia <jorge.garcia <at> openbravo.com> date: Wed Jun 10 13:09:56 2015 +0200 summary: Fixed issue 30082: Payment plan is updating wrong in some circumstances Payment plan is updating wrong if Payment Method is set as Automatic Receipt and a sales order is partially paid. The problem was that the function duplicates the value of the received amount created in the Complete process of the invoice, because the function searches all the payment details of the payment plan that has an invoice paid (invoicepaid column). The solution is to search those payment details that are not pre-paid and then update the payment plan. Now, the values are filled correctly. details: https://code.openbravo.com/erp/devel/pi/rev/ab5e14425861 changeset: 26910:ab5e14425861 user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Fri Jun 12 12:49:18 2015 +0200 summary: 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. diffstat: modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml | 28 +++------ 1 files changed, 10 insertions(+), 18 deletions(-) diffs (60 lines): diff -r 91f6d8a87c92 -r ab5e14425861 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 Fri Jun 12 11:48:26 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 @@ -904,7 +904,7 @@ END IF; END IF; - IF (cur_finaccpaymentmethod.ExecutionType<>'A') THEN + IF (cur_finaccpaymentmethod.ExecutionType<>'A') THEN UPDATE FIN_PAYMENT_SCHEDULE SET PAIDAMT = (SELECT COALESCE(sum(amount + COALESCE(writeoffamt, 0)), 0) FROM fin_payment_scheduledetail @@ -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; @@ -936,16 +930,15 @@ UPDATE FIN_PAYMENT SET DESCRIPTION = v_finpayment_desc WHERE FIN_PAYMENT_ID = v_FIN_PAYMENT_ID; - FOR cur_invoicepaid IN ( - select isinvoicepaid from fin_payment_scheduledetail fpsd - left join fin_payment_detail fpd on fpsd.fin_payment_detail_id=fpd.fin_payment_detail_id - left join fin_payment fp on fpd.fin_payment_id=fp.fin_payment_id - left join fin_payment_schedule ps ON ps.fin_payment_schedule_id = fpsd.fin_payment_schedule_invoice - WHERE ps.c_invoice_id =p_record_id - ) - LOOP + SELECT count(*) INTO v_count + FROM fin_payment_schedule fps + WHERE exists(select 1 + from fin_payment_scheduledetail fpsd + 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 (cur_invoicepaid.isinvoicepaid='Y')) 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) @@ -994,7 +987,6 @@ SET SO_CREDITUSED = COALESCE(SO_CREDITUSED,0) - v_ConvertedAmount WHERE C_BPARTNER_ID = v_BPartner_ID; END IF; - END LOOP; -- Automatic creation of financial transaction IF(cur_finaccpaymentmethod.CreateFinTransaction = 'Y' AND cur_finaccpaymentmethod.ExecutionType = 'M') THEN v_ResultStr:='Generating FIN_FINACC_TRANSACTION'; ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits