Account Invoice: Slow combinations when reconcile lines for amount

An invoice is related with a move that has 45 lines (account.move.line). Each line has same amount.

When try validate a stament, start do combinations [1] (from itertools). Start do 45, 44, 43, …41, 40… and not end.


A- Set new variable to do MAX combinations and abort.
B- iterate over combinations with a recursion, not using combinations() from itertools.
C- …

[1] account_invoice/ at 5.4 · tryton/account_invoice · GitHub

I guess you mean when try validate a statement. But there is no reconciliation when validating a statement (it is triggered manualy by the user).

So why not setting the invoice directly on the statement?

The reconciliation is a Knapsack problem - Wikipedia the current implementation is a naive brute force because we expected only small number of payment terms (certainly not 45 terms). Some heuristics exits that may find a solution faster.
But I think the problem is that having a payment terms of 45 lines is the real problem. With a term per month, it spreads over almost 4 years. I do not know business that can take such risk.

That can not be a solution because the problem will still be there: no reconciliation or payment.

I do not see how this could solve the problem. Indeed with recursion you will probably reach recursion limit.

Maybe an option would be to raise a warning when calling Invoice.get_reconcile_lines_for_amount with a list of lines to big (biggest than reconciliation_chunk). So the user will have to remove the invoice (or not use the pay wizard) and make the reconciliation manually (create the payment move manually).