bank-payment icon indicating copy to clipboard operation
bank-payment copied to clipboard

[14.0] account_payment_order: Performance problem when posting + reconciling transit moves

Open pedrobaeza opened this issue 3 years ago • 2 comments

Steps to reproduce:

  • Have a big bunch of invoices (200+).
  • Include all of them in a payment order.
  • Configure the payment mode to post transit moves.
  • Confirm the order, generate file, and click of "File successfully uploaded".

The operation will take a lot of time, or even not being able to finish depending on the timeouts.

Tracing down the problem, it's a proportional performance degradation on each loop of:

https://github.com/OCA/bank-payment/blob/485abeb889d344f2dda52adc71928967629ac71e/account_payment_order/models/bank_payment_line.py#L141

Selección_043

And it's due to a call over _compute_amount:

https://github.com/odoo/odoo/blob/062fb69f346873fe05ebb5d429ab3535fd1df5cc/addons/account/models/account_move.py#L1406

coming from:

https://github.com/odoo/odoo/blob/062fb69f346873fe05ebb5d429ab3535fd1df5cc/addons/account/models/account_move.py#L4997

that contains each time current invoices plus the old ones.

_compute_amount account.move(204346, 204864)
_compute_amount account.move(204320, 204346, 204864, 204319)
_compute_amount account.move(204318, 204864, 204320, 204346, 204319)
_compute_amount account.move(204317, 204864, 204320, 204346, 204318, 204319)
_compute_amount account.move(204315, 204864, 204320, 204346, 204317, 204318, 204319)
_compute_amount account.move(204313, 204864, 204320, 204346, 204315, 204317, 204318, 204319)
_compute_amount account.move(204312, 204320, 204864, 204313, 204346, 204315, 204317, 204318, 204319)
_compute_amount account.move(203154, 204864, 204320, 204312, 204313, 204346, 204315, 204317, 204318, 204319)
_compute_amount account.move(203153, 204864, 204320, 203154, 204312, 204313, 204346, 204315, 204317, 204318, 204319)
_compute_amount account.move(203152, 204320, 204864, 203153, 203154, 204312, 204313, 204346, 204315, 204317, 204318, 204319)
_compute_amount account.move(203151, 204864, 204320, 203152, 203153, 203154, 204312, 204313, 204346, 204315, 204317, 204318, 204319)
_compute_amount account.move(203148, 204864, 202753, 204320, 203151, 203152, 203153, 203154, 204312, 204313, 204346, 204315, 204317, 204318, 204319)
_compute_amount account.move(203145, 204864, 204320, 202753, 203148, 203151, 203152, 203153, 203154, 204312, 204313, 204346, 204315, 204317, 204318, 204319)
...

This can be an effect of the depends for the field or bad handling of the ORM, but anyway, there's no clean solution having some parts on Odoo core and not having clear the root source.

My first option was to aggregate all move lines to reconcile and call it once, but this may do undesired reconciliations when having same amounts, mixing partners and so on.

@Tecnativa TT39832

pedrobaeza avatar Oct 06 '22 19:10 pedrobaeza

Have you experimented this, @sbidoul @alexis-via ?

pedrobaeza avatar Oct 06 '22 19:10 pedrobaeza

I haven't experimented this, but I probably never had such a high volume of payment lines in a single payment order.

alexis-via avatar Oct 06 '22 20:10 alexis-via

Resolved in #979

pedrobaeza avatar Jan 03 '23 08:01 pedrobaeza