From 550eb0b73c521ca0c19a31967dc3aa6a5c2516ea Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 27 Oct 2021 15:53:02 +0200 Subject: [PATCH] [IMP] account: Convert _onchange_sale_tax into compute method --- addons/account/models/res_config_settings.py | 23 ++++++++------------ addons/account/tests/test_settings.py | 3 --- addons/website_sale/tests/test_customize.py | 1 - 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index e138e442bf4..443c6cb9a5a 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -80,11 +80,13 @@ class ResConfigSettings(models.TransientModel): group_show_line_subtotals_tax_excluded = fields.Boolean( "Show line subtotals without taxes (B2B)", implied_group='account.group_show_line_subtotals_tax_excluded', - group='base.group_portal,base.group_user,base.group_public') + group='base.group_portal,base.group_user,base.group_public', + compute='_compute_group_show_line_subtotals', store=True, readonly=False) group_show_line_subtotals_tax_included = fields.Boolean( "Show line subtotals with taxes (B2C)", implied_group='account.group_show_line_subtotals_tax_included', - group='base.group_portal,base.group_user,base.group_public') + group='base.group_portal,base.group_user,base.group_public', + compute='_compute_group_show_line_subtotals', store=True, readonly=False) group_show_sale_receipts = fields.Boolean(string='Sale Receipt', implied_group='account.group_sale_receipts') group_show_purchase_receipts = fields.Boolean(string='Purchase Receipt', @@ -154,18 +156,11 @@ class ResConfigSettings(models.TransientModel): self.has_chart_of_accounts = bool(self.company_id.chart_template_id) self.has_accounting_entries = self.env['account.chart.template'].existing_accounting(self.company_id) - @api.onchange('show_line_subtotals_tax_selection') - def _onchange_sale_tax(self): - if self.show_line_subtotals_tax_selection == "tax_excluded": - self.update({ - 'group_show_line_subtotals_tax_included': False, - 'group_show_line_subtotals_tax_excluded': True, - }) - else: - self.update({ - 'group_show_line_subtotals_tax_included': True, - 'group_show_line_subtotals_tax_excluded': False, - }) + @api.depends('show_line_subtotals_tax_selection') + def _compute_group_show_line_subtotals(self): + for wizard in self: + wizard.group_show_line_subtotals_tax_included = wizard.show_line_subtotals_tax_selection == "tax_included" + wizard.group_show_line_subtotals_tax_excluded = wizard.show_line_subtotals_tax_selection == "tax_excluded" @api.onchange('group_analytic_accounting') def onchange_analytic_accounting(self): diff --git a/addons/account/tests/test_settings.py b/addons/account/tests/test_settings.py index 2aabe3345ce..595ff571405 100644 --- a/addons/account/tests/test_settings.py +++ b/addons/account/tests/test_settings.py @@ -19,21 +19,18 @@ class TestSettings(AccountTestInvoicingCommon): def switch_tax_settings(self, config): config.show_line_subtotals_tax_selection = "tax_excluded" - config._onchange_sale_tax() config.flush() config.execute() self.assertEqual(self.env.user.has_group('account.group_show_line_subtotals_tax_excluded'), True) self.assertEqual(self.env.user.has_group('account.group_show_line_subtotals_tax_included'), False) config.show_line_subtotals_tax_selection = "tax_included" - config._onchange_sale_tax() config.flush() config.execute() self.assertEqual(self.env.user.has_group('account.group_show_line_subtotals_tax_excluded'), False) self.assertEqual(self.env.user.has_group('account.group_show_line_subtotals_tax_included'), True) config.show_line_subtotals_tax_selection = "tax_excluded" - config._onchange_sale_tax() config.flush() config.execute() self.assertEqual(self.env.user.has_group('account.group_show_line_subtotals_tax_excluded'), True) diff --git a/addons/website_sale/tests/test_customize.py b/addons/website_sale/tests/test_customize.py index f15086100c1..b29b9fc9e6e 100644 --- a/addons/website_sale/tests/test_customize.py +++ b/addons/website_sale/tests/test_customize.py @@ -308,7 +308,6 @@ class TestUi(HttpCaseWithUserDemo, HttpCaseWithUserPortal): # activate b2c config = self.env['res.config.settings'].create({}) config.show_line_subtotals_tax_selection = "tax_included" - config._onchange_sale_tax() config.execute() self.start_tour("/", 'shop_list_view_b2c', login="admin")