From cf3d3050f5fe272ba16bc6d80038bea608d9e41d Mon Sep 17 00:00:00 2001 From: william-andre Date: Wed, 27 Mar 2024 08:46:05 +0000 Subject: [PATCH] [FIX] account,l10n_be: allow to change the chart template even with demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When in demo mode, we always want to be able to change the CoA * to remove friction when demoing: no need to be overly safe * to ensure that `test_all_l10n` always works even if we load a CoA in `.create` closes odoo/odoo#162299 X-original-commit: cceb4e823f7a697076615a13c2b47bc6dbdbaedb Related: odoo/enterprise#60993 Signed-off-by: Habib Ayob (ayh) Signed-off-by: William André (wan) --- addons/account/tests/test_chart_template.py | 33 +++++++++++++++++++++ addons/l10n_be/demo/account_demo.py | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/addons/account/tests/test_chart_template.py b/addons/account/tests/test_chart_template.py index 71571d347f2..ce110d377fa 100644 --- a/addons/account/tests/test_chart_template.py +++ b/addons/account/tests/test_chart_template.py @@ -25,6 +25,8 @@ def test_get_data(self, template_code): 'currency_id': 'base.EUR', 'property_account_income_categ_id': 'test_account_income_template', 'property_account_expense_categ_id': 'test_account_expense_template', + 'property_account_receivable_id': 'test_account_receivable_template', + 'property_account_payable_id': 'test_account_payable_template', }, 'account.tax.group': { 'tax_group_taxes': { @@ -62,6 +64,16 @@ def test_get_data(self, template_code): } }, 'account.account': { + 'test_account_receivable_template': { + 'name': 'property_receivable_account', + 'code': '411111', + 'account_type': 'asset_receivable', + }, + 'test_account_payable_template': { + 'name': 'property_payable_account', + 'code': '421111', + 'account_type': 'liability_payable', + }, 'test_account_income_template': { 'name': 'property_income_account', 'code': '222221', @@ -552,6 +564,27 @@ class TestChartTemplate(TransactionCase): # silently ignore if the field doesn't exist (yet) self.env['account.chart.template'].try_loading('test', company=company, install_demo=False) + def test_change_coa(self): + def _get_chart_template_mapping(self, get_all=False): + return {'other_test': { + 'name': 'test', + 'country_id': None, + 'country_code': None, + 'module': 'account', + 'parent': None, + }} + + with ( + patch.object(AccountChartTemplate, '_get_chart_template_mapping', _get_chart_template_mapping), + patch.object(AccountChartTemplate, '_get_chart_template_data', side_effect=test_get_data, autospec=True) + ): + self.env['account.chart.template'].try_loading('other_test', company=self.company_1, install_demo=True) + self.assertEqual(self.company_1.chart_template, 'other_test') + + with patch.object(AccountChartTemplate, '_get_chart_template_data', side_effect=test_get_data, autospec=True): + self.env['account.chart.template'].try_loading('test', company=self.company_1, install_demo=True) + self.assertEqual(self.company_1.chart_template, 'test') + def test_update_tax_with_non_existent_tag(self): """ Tests that when we update the CoA with a tax that has a tag that does not exist yet we raise an error. Typical use case is when the code got updated but the module haven't been updated (-u). diff --git a/addons/l10n_be/demo/account_demo.py b/addons/l10n_be/demo/account_demo.py index 089bb358257..c0cde7edc60 100644 --- a/addons/l10n_be/demo/account_demo.py +++ b/addons/l10n_be/demo/account_demo.py @@ -7,7 +7,7 @@ class AccountChartTemplate(models.AbstractModel): @api.model def _get_demo_data(self, company=False): demo_data = super()._get_demo_data(company) - if company.account_fiscal_country_id.code == 'BE': + if company.chart_template.startswith('be'): cid = company.id account_data = demo_data.setdefault('account.account', {}) account_data.update({