From facf4c57761b988675fb1f3d8912a714fdb852e3 Mon Sep 17 00:00:00 2001 From: josep-tecnativa Date: Fri, 13 Oct 2023 09:24:14 +0200 Subject: [PATCH 1/2] [IMP] account_financial_report: test performance improvement --- .../tests/test_aged_partner_balance.py | 17 ++++++++++++++--- .../tests/test_general_ledger.py | 10 ++++++++++ .../tests/test_journal_ledger.py | 10 ++++++++++ .../tests/test_open_items.py | 10 ++++++++++ .../tests/test_trial_balance.py | 10 ++++++++++ .../tests/test_vat_report.py | 10 ++++++++++ 6 files changed, 64 insertions(+), 3 deletions(-) diff --git a/account_financial_report/tests/test_aged_partner_balance.py b/account_financial_report/tests/test_aged_partner_balance.py index b1c0e6ca..69b86806 100644 --- a/account_financial_report/tests/test_aged_partner_balance.py +++ b/account_financial_report/tests/test_aged_partner_balance.py @@ -6,9 +6,20 @@ from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, test_reports class TestAgedPartnerBalance(TransactionCase): - def setUp(self): - super().setUp() - self.wizard_model = self.env["aged.partner.balance.report.wizard"] + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls.wizard_model = cls.env["aged.partner.balance.report.wizard"] def test_report(self): """Check that report is produced correctly.""" diff --git a/account_financial_report/tests/test_general_ledger.py b/account_financial_report/tests/test_general_ledger.py index c8a2aa70..2e9187bc 100644 --- a/account_financial_report/tests/test_general_ledger.py +++ b/account_financial_report/tests/test_general_ledger.py @@ -17,6 +17,16 @@ class TestGeneralLedgerReport(AccountTestInvoicingCommon): @classmethod def setUpClass(cls, chart_template_ref=None): super().setUpClass(chart_template_ref=chart_template_ref) + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) cls.before_previous_fy_year = fields.Date.from_string("2014-05-05") cls.previous_fy_date_start = fields.Date.from_string("2015-01-01") cls.previous_fy_date_end = fields.Date.from_string("2015-12-31") diff --git a/account_financial_report/tests/test_journal_ledger.py b/account_financial_report/tests/test_journal_ledger.py index 62b56e5e..bd343932 100644 --- a/account_financial_report/tests/test_journal_ledger.py +++ b/account_financial_report/tests/test_journal_ledger.py @@ -18,6 +18,16 @@ class TestJournalReport(AccountTestInvoicingCommon): @classmethod def setUpClass(cls, chart_template_ref=None): super().setUpClass(chart_template_ref=chart_template_ref) + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) cls.AccountObj = cls.env["account.account"] cls.InvoiceObj = cls.env["account.move"] cls.JournalObj = cls.env["account.journal"] diff --git a/account_financial_report/tests/test_open_items.py b/account_financial_report/tests/test_open_items.py index b490ca0e..532d896e 100644 --- a/account_financial_report/tests/test_open_items.py +++ b/account_financial_report/tests/test_open_items.py @@ -12,6 +12,16 @@ class TestOpenItems(AccountTestInvoicingCommon): @classmethod def setUpClass(cls, chart_template_ref=None): super().setUpClass(chart_template_ref=chart_template_ref) + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) def test_partner_filter(self): partner_1 = self.env.ref("base.res_partner_1") diff --git a/account_financial_report/tests/test_trial_balance.py b/account_financial_report/tests/test_trial_balance.py index 37d713b0..8128267b 100644 --- a/account_financial_report/tests/test_trial_balance.py +++ b/account_financial_report/tests/test_trial_balance.py @@ -13,6 +13,16 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon): @classmethod def setUpClass(cls, chart_template_ref=None): super().setUpClass(chart_template_ref=chart_template_ref) + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) # Remove previous account groups and related invoices to avoid conflicts group_obj = cls.env["account.group"] cls.group1 = group_obj.create({"code_prefix_start": "1", "name": "Group 1"}) diff --git a/account_financial_report/tests/test_vat_report.py b/account_financial_report/tests/test_vat_report.py index 91776af1..04cb9a5b 100644 --- a/account_financial_report/tests/test_vat_report.py +++ b/account_financial_report/tests/test_vat_report.py @@ -49,6 +49,16 @@ class TestVATReport(AccountTestInvoicingCommon): @classmethod def setUpClass(cls, chart_template_ref=None): super().setUpClass(chart_template_ref=chart_template_ref) + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) cls.date_from = time.strftime("%Y-%m-01") cls.date_to = time.strftime("%Y-%m-28") cls.company = cls.env.user.company_id From ab5ea0120a903021369a89acddfbd5742fa67552 Mon Sep 17 00:00:00 2001 From: josep-tecnativa Date: Fri, 13 Oct 2023 09:30:51 +0200 Subject: [PATCH 2/2] [IMP] account_tax_balance: test performance improvement --- .../tests/test_account_tax_balance.py | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/account_tax_balance/tests/test_account_tax_balance.py b/account_tax_balance/tests/test_account_tax_balance.py index 96a639ff..e0025f6c 100644 --- a/account_tax_balance/tests/test_account_tax_balance.py +++ b/account_tax_balance/tests/test_account_tax_balance.py @@ -17,28 +17,39 @@ from odoo.addons.account.tests.common import AccountTestInvoicingCommon @odoo.tests.tagged("post_install", "-at_install") class TestAccountTaxBalance(HttpCase): - def setUp(self): - super().setUp() - self.env.user.groups_id = [(4, self.env.ref("account.group_account_user").id)] - self.company = self.env.user.company_id - self.range_type = self.env["date.range.type"].create( + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls.env.user.groups_id = [(4, cls.env.ref("account.group_account_user").id)] + cls.company = cls.env.user.company_id + cls.range_type = cls.env["date.range.type"].create( {"name": "Fiscal year", "allow_overlap": False} ) - self.range_generator = self.env["date.range.generator"] - self.current_year = datetime.now().year - self.current_month = datetime.now().month - range_generator = self.range_generator.create( + cls.range_generator = cls.env["date.range.generator"] + cls.current_year = datetime.now().year + cls.current_month = datetime.now().month + range_generator = cls.range_generator.create( { - "date_start": "%s-01-01" % self.current_year, - "name_prefix": "%s-" % self.current_year, - "type_id": self.range_type.id, + "date_start": "%s-01-01" % cls.current_year, + "name_prefix": "%s-" % cls.current_year, + "type_id": cls.range_type.id, "duration_count": 1, "unit_of_time": str(MONTHLY), "count": 12, } ) range_generator.action_apply() - self.range = self.env["date.range"] + cls.range = cls.env["date.range"] def test_tax_balance(self): previous_taxes_ids = (