Open Balance is wrong calculated with payment selection
Description
When you use the payment selection to pay several invoices with one payment the value of the BusinessPartner field TotalOpenBalance is not calculated the right way. The paid value is subtracted two times.
Reproducing this issue: For example I created a new businesspartner (as a vendor). It has a TOB of 0,00. Then I create one Invoice (Vendor) with an amount of 20,- and one with 30,00 . The TOB of the businesspartner is - 50,00. Now I go to the Payment Selection. I use the "Create From" Button and the the "Prepare Payment" to create one single prepared payment (check) for both invoices. Then I use the "Payment print/export" window to export the payment. After that a payment is created and the TOP field of the Business Partner is 50,00 (not 0,00 as it should be).
For me it seems that the MAllocationHdr updates the TotalOpenBalance value while completing (completeIt() calls updateBP() which recalculates this). But the Payment also updates TotalOpenBalance (in completeIt()). That seems a double update. I am not sure which one of these two updates is the right and which the wrong.
Environment
None
Attachments
1
IDEMPIERE-2435.patch
02 Feb, 2015
Activity
Thomas Bayen
February 2, 2015 at 1:01 AM
Just for the files: The code path that sets the TOB field in the MPayment class is for the case of a prepayment. There is a check if there are MPaymentAllocate records. If these exists the TOB will be updated by them and not by the MPayment code. But it was not checked if the Payment belongs to a PaymentSelection. This check is added by the given patch.
Carlos Ruiz
February 2, 2015 at 12:16 AM
Hi @Thomas Bayen, attached a patch that I think it solves the issue, can you please test it and provide feedback?
When you use the payment selection to pay several invoices with one payment the value of the BusinessPartner field TotalOpenBalance is not calculated the right way. The paid value is subtracted two times.
Reproducing this issue: For example I created a new businesspartner (as a vendor). It has a TOB of 0,00. Then I create one Invoice (Vendor) with an amount of 20,- and one with 30,00 . The TOB of the businesspartner is - 50,00. Now I go to the Payment Selection. I use the "Create From" Button and the the "Prepare Payment" to create one single prepared payment (check) for both invoices. Then I use the "Payment print/export" window to export the payment. After that a payment is created and the TOP field of the Business Partner is 50,00 (not 0,00 as it should be).
For me it seems that the MAllocationHdr updates the TotalOpenBalance value while completing (completeIt() calls updateBP() which recalculates this). But the Payment also updates TotalOpenBalance (in completeIt()). That seems a double update. I am not sure which one of these two updates is the right and which the wrong.