[FIX] account,l10n_be: allow to change the chart template even with demo

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 `<res.company>.create`

closes odoo/odoo#162299

X-original-commit: cceb4e823f7a697076615a13c2b47bc6dbdbaedb
Related: odoo/enterprise#60993
Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
william-andre
2024-04-22 11:51:27 +00:00
parent 6944eb3118
commit cf3d3050f5
2 changed files with 34 additions and 1 deletions
@@ -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).
+1 -1
View File
@@ -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({