From 5901e7c5533cdb24349b9010dc5e67ddea2cb773 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Thu, 25 Mar 2021 14:48:13 +0000 Subject: [PATCH] [FIX] account: prevent excess calls of _get_lines_onchange_currency That method iterates over move lines: https://github.com/odoo/odoo/blob/7623a0c771495cd41bf40af37c0d2b6e4beb7cdc/addons/stock_account/models/account_move.py#L16-L18 So, we have O(n^2) complexity at least. It leads to timeout error on invoices with few hundres products. After this commit it takes 70 seconds to confirm an invoice with 450 lines: 23527 11.038 56.530 (Number of queries / Query time, sec / Remaining time, sec) --- https://github.com/odoo/odoo/commit/9e1aec7873a935b287b4b3c5dbc2688acee5422a opw-2488458 closes odoo/odoo#68797 X-original-commit: 176ecb1239f7e0a8e938de996d174b9c5bf930f4 Signed-off-by: Laurent Smet --- addons/account/models/account_move.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 923893e659a..ff5b80aee66 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1267,12 +1267,9 @@ class AccountMove(models.Model): total_residual_currency = 0.0 total = 0.0 total_currency = 0.0 - currencies = set() + currencies = move._get_lines_onchange_currency().currency_id for line in move.line_ids: - if line.currency_id and line in move._get_lines_onchange_currency(): - currencies.add(line.currency_id) - if move._payment_state_matters(): # === Invoices === @@ -1313,7 +1310,7 @@ class AccountMove(models.Model): move.amount_residual_signed = total_residual move.amount_total_in_currency_signed = abs(move.amount_total) if move.move_type == 'entry' else -(sign * move.amount_total) - currency = len(currencies) == 1 and currencies.pop() or move.company_id.currency_id + currency = currencies if len(currencies) == 1 else move.company_id.currency_id # Compute 'payment_state'. new_pmt_state = 'not_paid' if move.move_type != 'entry' else False