[IMP] account, l10n_xx: change CoA loading methods

Before, we only had a public method that installed
the CoA for the current active company.

With the multi-company changes, it was not
possible anymore to install a module with a
demo company and then have the CoA installed
in that demo company correctly.

We changed that public method to be able to
put an extra optional parameter and shortened
its name to try_loading instead of
try_loading_for_current_company.  The method that
it calls when there is no chart installed
is made private and renamed to _load.

closes odoo/odoo#35703

Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
Josse Colpaert
2019-08-14 08:42:27 +00:00
parent 275dcfa412
commit f8d4bf4499
64 changed files with 77 additions and 79 deletions
+11 -12
View File
@@ -164,21 +164,24 @@ class AccountChartTemplate(models.Model):
'chart_template_id': self.id,
}
def try_loading_for_current_company(self):
def try_loading(self, company=False):
""" Installs this chart of accounts for the current company if not chart
of accounts had been created for it yet.
"""
# do not use `request.env` here, it can cause deadlocks
if request and hasattr(request, 'allowed_company_ids'):
company = self.env['res.company'].browse(request.allowed_company_ids[0])
else:
company = self.env.company
if not company:
if request and hasattr(request, 'allowed_company_ids'):
company = self.env['res.company'].browse(request.allowed_company_ids[0])
else:
company = self.env.company
# If we don't have any chart of account on this company, install this chart of account
if not company.chart_template_id and not self.existing_accounting(company):
for template in self:
template.load_for_current_company(15.0, 15.0)
template.with_context(default_company_id=company.id)._load(15.0, 15.0, company)
def load_for_current_company(self, sale_tax_rate, purchase_tax_rate):
try_loading_for_current_company = try_loading
def _load(self, sale_tax_rate, purchase_tax_rate, company):
""" Installs this chart of accounts on the current company, replacing
the existing one if it had already one defined. If some accounting entries
had already been made, this function fails instead, triggering a UserError.
@@ -188,12 +191,8 @@ class AccountChartTemplate(models.Model):
"""
self.ensure_one()
# do not use `request.env` here, it can cause deadlocks
if request and hasattr(request, 'allowed_company_ids'):
company = self.env['res.company'].browse(request.allowed_company_ids[0])
else:
company = self.env.company
# Ensure everything is translated to the company's language, not the user's one.
self = self.with_context(lang=company.partner_id.lang)
self = self.with_context(lang=company.partner_id.lang, company=company)
if not self.env.is_admin():
raise AccessError(_("Only administrators can load a charf of accounts"))
+1 -1
View File
@@ -94,7 +94,7 @@ class ResConfigSettings(models.TransientModel):
self.env.ref('base.group_user').write({'implied_ids': [(4, self.env.ref('product.group_sale_pricelist').id)]})
""" install a chart of accounts for the given company (if required) """
if self.chart_template_id and self.chart_template_id != self.company_id.chart_template_id:
self.chart_template_id.load_for_current_company(15.0, 15.0)
self.chart_template_id._load(15.0, 15.0, self.env.company)
@api.depends('company_id')
def _compute_has_chart_of_accounts(self):
@@ -56,7 +56,7 @@ class AccountingSavepointCase(SavepointCase):
cls.env.user.company_id = company
chart_template = cls.env['account.chart.template'].browse(chart_template.id)
chart_template.load_for_current_company(15.0, 15.0)
chart_template.try_loading()
# The currency could be different after the installation of the chart template.
company.write({'currency_id': kwargs.get('currency_id', cls.env.user.company_id.currency_id.id)})
@@ -48,4 +48,4 @@ class TestAllL10n(SingleTransactionCase):
_logger.info(msg)
with self.subTest(msg=msg):
with self.cr.savepoint():
coa.try_loading_for_current_company()
coa.try_loading()
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ae.uae_chart_template_standard')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ar.ar_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_at.austria_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_au.l10n_au_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_be.l10nbe_chart_template')]"/>
</function>
</data>
+1 -1
View File
@@ -10,7 +10,7 @@ class TestUBL(common.TransactionCase):
# Force user Belgium country.
self.env.user.company_id = self.env['res.company'].create({'name': 'MyCompany'})
self.env.user.company_id.country = self.env.ref('base.be')
self.env.ref('l10n_be.l10nbe_chart_template').load_for_current_company(False, False)
self.env.ref('l10n_be.l10nbe_chart_template').try_loading()
self.partner_id = self.env['res.partner'].create({'name': 'TestUser', 'vat': 'BE0123456789'})
def test_ubl_invoice_import(self):
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_bo.bo_chart_template')]"/>
</function>
</data>
@@ -3182,7 +3182,7 @@
</record>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_br.l10n_br_account_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ca.ca_en_chart_template_en')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ch.l10nch_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_cl.cl_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_cn_small_business.l10n_chart_china_small_business')]"/>
</function>
</data>
@@ -12,7 +12,7 @@
<field name="default_pos_receivable_account_id" ref="account_1124" />
</record>
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_cn_standard.l10n_chart_china_standard_business')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_co.l10n_co_chart_template_generic')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_cr.account_chart_template_0')]"/>
</function>
</data>
+2 -3
View File
@@ -15,9 +15,8 @@ class AccountChartTemplate(models.Model):
return res
# Write paperformat and report template used on company
def load_for_current_company(self, sale_tax_rate, purchase_tax_rate):
res = super(AccountChartTemplate, self).load_for_current_company(sale_tax_rate, purchase_tax_rate)
company = self.env.company
def _load(self, sale_tax_rate, purchase_tax_rate, company):
res = super(AccountChartTemplate, self)._load(sale_tax_rate, purchase_tax_rate, company)
if company.country_id.code == 'DE':
company.write({'external_report_layout_id': self.env.ref('l10n_de.external_layout_din5008').id,
'paperformat_id': self.env.ref('l10n_de.paperformat_euro_din').id})
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_de_skr03.l10n_de_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_de_skr04.l10n_chart_de_skr04')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_do.do_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ec.ec_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_es.account_chart_template_pymes')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_et.l10n_et')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_fr.l10n_fr_pcg_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_generic_coa.configurable_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_gr.l10n_gr_chart_template')]"/>
</function>
</data>
@@ -72,7 +72,7 @@
]"/>
</record>
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_gt.cuentas_plantilla')]"/>
</function>
</data>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_hk.l10n_hk_chart_template')]"/>
</function>
</odoo>
@@ -72,7 +72,7 @@
]"/>
</record>
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_hn.cuentas_plantilla')]"/>
</function>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_hr.l10n_hr_chart_template_rrif')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_hu.hungarian_chart_template')]"/>
</function>
</data>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ie.l10n_ie')]"/>
</function>
</odoo>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_in.indian_chart_template_standard')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_it.l10n_it_chart_template_generic')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_jp.l10n_jp1')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_lu.lu_2011_chart_1')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ma.l10n_kzc_temp_chart')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_mn.mn_chart_1')]"/>
</function>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_mx.mx_coa')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_nl.l10nnl_chart_template')]"/>
</function>
</data>
@@ -6,10 +6,10 @@ from odoo import api, fields, models, _
class AccountChartTemplate(models.Model):
_inherit = 'account.chart.template'
def load_for_current_company(self, sale_tax_rate, purchase_tax_rate):
def _load(self, sale_tax_rate, purchase_tax_rate, company):
# Add tag to 999999 account
res = super(AccountChartTemplate, self).load_for_current_company(sale_tax_rate, purchase_tax_rate)
if self.env.company.country_id.code == 'NL':
res = super(AccountChartTemplate, self)._load(sale_tax_rate, purchase_tax_rate, company)
if company.country_id.code == 'NL':
account = self.env['account.account'].search([('code', '=', '999999'), ('company_id', '=', self.env.company.id)])
if account:
account.tag_ids = [(4, self.env.ref('l10n_nl.account_tag_12').id)]
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_no.no_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_nz.l10n_nz_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_pa.l10npa_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_pe.pe_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_pl.pl_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_pt.pt_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ro.ro_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_sa.account_arabic_coa_general')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_sg.sg_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_si.gd_chart')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_syscohada.syscohada_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_th.chart')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_tr.l10ntr_tek_duzen_hesap')]"/>
</function>
</data>
@@ -31,7 +31,7 @@
<field name="default_pos_receivable_account_id" ref="ua_ias_1122" />
</record>
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ua.l10n_ua_psbo_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_uk.l10n_uk')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_uy.uy_chart_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_ve.ve_chart_template_amd')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_vn.vn_template')]"/>
</function>
</data>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<function model="account.chart.template" name="try_loading_for_current_company">
<function model="account.chart.template" name="try_loading">
<value eval="[ref('l10n_za.default_chart_template')]"/>
</function>
@@ -18,7 +18,7 @@ class TestPurchaseOrderReport(common.TransactionCase):
# Create a new company and set CoA
self.company_id = self.env['res.company'].create({'name': 'new_company'})
self.env.user.company_id = self.company_id
self.env.ref('l10n_generic_coa.configurable_chart_template').load_for_current_company(False, False)
self.env.ref('l10n_generic_coa.configurable_chart_template').try_loading()
def test_00_purchase_order_report(self):
uom_dozen = self.env.ref('uom.product_uom_dozen')