Skip to content

Commit

Permalink
[FIX] account: speedup _compute_tax_country_id
Browse files Browse the repository at this point in the history
Speedup computation of tax_country_id by first filtering
on record with fiscal_position_id.foreign_vat. Then group records
without foreign_vat by company_id and call __setitem__ on each group.

In the best case (1 company and no record with foreign_vat) this gives
a speedup of 7.37s -> 450ms for 1000 records.
This also speeds up the importing of account_bank_statements.

opw-3576526

closes odoo#144164

X-original-commit: 7c7e24d
Signed-off-by: Florian Gilbert (flg) <[email protected]>
  • Loading branch information
Aurelienvd committed Dec 4, 2023
1 parent d7b03f7 commit d507a86
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from odoo.exceptions import RedirectWarning, UserError, ValidationError, AccessError
from odoo.osv import expression
from odoo.tools import float_compare, float_is_zero, date_utils, email_split, email_re, html_escape, is_html_empty, sql
from odoo.tools.misc import format_amount, formatLang, format_date, get_lang
from odoo.tools.misc import format_amount, formatLang, format_date, get_lang, groupby

from datetime import date, timedelta
from collections import defaultdict
Expand Down Expand Up @@ -2080,11 +2080,11 @@ def _compute_show_reset_to_draft_button(self):

@api.depends('company_id.account_fiscal_country_id', 'fiscal_position_id.country_id', 'fiscal_position_id.foreign_vat')
def _compute_tax_country_id(self):
for record in self:
if record.fiscal_position_id.foreign_vat:
record.tax_country_id = record.fiscal_position_id.country_id
else:
record.tax_country_id = record.company_id.account_fiscal_country_id
foreign_vat_records = self.filtered(lambda r: r.fiscal_position_id.foreign_vat)
for fiscal_position_id, record_group in groupby(foreign_vat_records, key=lambda r: r.fiscal_position_id):
self.env['account.move'].concat(*record_group).tax_country_id = fiscal_position_id.country_id
for company_id, record_group in groupby((self-foreign_vat_records), key=lambda r: r.company_id):
self.env['account.move'].concat(*record_group).tax_country_id = company_id.account_fiscal_country_id

@api.depends('tax_country_id.code')
def _compute_tax_country_code(self):
Expand Down

0 comments on commit d507a86

Please sign in to comment.