← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 672479] Re: Account_payment_extension, incorrect debt calculation

 

Hi Eric and Jordi,
unfortunately, it's not that easy. You're right: the original code is wrong and Eric's is an improvement but does not yet solve all the cases. We must ensure the code works correctly in the following scenarios:

1- Account moves totally reconciled

The following ones assume partial reconciliation:

2- Account moves in payment orders with direct payment move (payment account move done in the payment order)
3- Account moves in payment orders with payment move from statement and after the statement has been validated
4- Account moves in payment orders with payment move from statement and before the statement has been validated
5- Account moves included in two (or more) mixed payment orders: 1 with direct payment and another one from statement and after the statement has been validated
6- Account moves included in two (or more) mixed payment orders: 1 with direct payment and another one from statement and before the statement has been validated

If I analyzed it correctly, my original code only works for (1) and (2)
and Eric's would work for (1), (2), (3), (4), (5) but not for (6). In
the latter case, supposing the account move has been partially paid with
two payments of 350 each, one with direct payment move and the other one
with statement-based moves, the values we would get would be:

Invoice = 1500
Paid = 350
Unreconciled = 350

With this example it may seem that using:

debt = min(debt - paid, max(0.0, unreconciled + paid))

would work, but that would break some of the other scenarios. So I think we must change the previous SQL statement. 
Given that the three of us agree at least in that Eric's proposal fixes most usual scenarios, I've applied Eric's patch right away and then take a look at what can be done at SQL level to fix the 6th and rarest case.

Fix has been commited in r4685.

Thanks to both Eric and Jordi for reporting and giving your feedback.

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/672479

Title:
  Account_payment_extension, incorrect debt calculation

Status in OpenObject Addons Modules:
  Won't Fix

Bug description:
  Using 5.15, I try to pay one supplier throught the "payable payment" menu. I create a new paiement order and then click on "Select invoices to pay/receive payment".
Some invoices do not appear in the list which are clearly unpaid. I went to analyze the code and cannot understand current calculation which seems to me wrong as it is (in account_payment_extension/account_line_move.py/def amount_to_pay).
eg: invoice supplier total= 1500. Paid= 800, amount to be paid still =700.
If I take the following code and print the variables
(...)
            else:
                if not unreconciled:
                    unreconciled = debt
                if debt > 0:
                    debt = min(debt - paid, max(0.0, unreconciled - paid))
                else:
                    debt = max(debt - paid, min(0.0, unreconciled - paid))
(...)
I have debt = 1500, which is correct
I have paid = 800, which is correct
I have unreconciled = 700 which is still correct.
But then if I make the calculation according to those variable, I get the following:
debt = min (1500 - 800, max (0, 700-800)) = min(700,0) = 0 and the invoice never appears in the list!
I do not understand fully understand the meaning/need of above "if test" but it seems to me its purpose is to take the min quantity between the payment system and the reconcilied invoice system as the 2 systems work independantly. I would then propose better this code, which fits my way of working:

                if debt > 0:
#                    debt = min(debt - paid, max(0.0, unreconciled - paid))
                    debt = min(debt - paid, max(0.0, unreconciled))
                else:
#                    debt = max(debt - paid, min(0.0, unreconciled - paid))
                    debt = max(debt - paid, min(0.0, unreconciled))
In this case if both payment system and reconciled system are synchronised or not, the information is always correct.

Still not completely sure of all the impacts so advises are welcome!





References