From ad2feb07f0bc2114f85e0ced24392da348b80c29 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Fri, 24 May 2019 15:01:18 +0000 Subject: [PATCH] [FIX] base, account: allow AllL10n test case to start Since a5b6f31, an attribute allowed_company_ids is set on request when calling the module button_immediate_install method. This method is called during the test TestAllL10n which does not have a bound request and makes it fail. With this commit, the attribute is set only if request is bound. By the way, a small improvement is added in the test. Before this commit, when the test was failing because of the button_immediate_install, it was immediately stopped. The same problem was arising during the test method, it was stopped at the first failure. As this test is run as a nightly test, one have to wait the next day to discover the next problem. With this commit, the exceptions are catched during the l10n_ modules installation and a simple error line is written in the logs. That way, the runbot will still detect the error. Also, the main test method that installs all the chart of accounts splits those install into subtests. This prevent the method to stop at first failure. closes odoo/odoo#33654 Signed-off-by: Christophe Monniez (moc) --- addons/account/tests/test_account_all_l10n.py | 15 +++++++++++---- odoo/addons/base/models/ir_module.py | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/account/tests/test_account_all_l10n.py b/addons/account/tests/test_account_all_l10n.py index 23fb0616a64..7e916ba60bb 100644 --- a/addons/account/tests/test_account_all_l10n.py +++ b/addons/account/tests/test_account_all_l10n.py @@ -27,7 +27,10 @@ class TestAllL10n(SingleTransactionCase): _logger.info("Modules to install: %s" % [x.name for x in l10n_mods]) for mod in l10n_mods: _logger.info('Installing l10n module %s' % mod.name) - mod.button_immediate_install() + try: + mod.button_immediate_install() + except Exception: + _logger.error('Failure during installation of module "%s"', mod.name) # Now that new modules are installed, we have to reset the environment api.Environment.reset() cls.env = api.Environment(cls.cr, odoo.SUPERUSER_ID, {}) @@ -36,9 +39,13 @@ class TestAllL10n(SingleTransactionCase): coas = self.env['account.chart.template'].search([]) for coa in coas: cname = 'company_%s' % str(coa.id) - _logger.info('Testing COA: %s (company: %s)' % (coa.name, cname)) comp = self.env['res.company'].create({ 'name': cname, }) - self.env.company_id = comp - coa.try_loading_for_current_company() + self.env.user.company_ids += comp + self.env.user.company_id = comp + msg = 'Testing COA: %s (company: %s)' % (coa.name, cname) + _logger.info(msg) + with self.subTest(msg=msg): + with self.cr.savepoint(): + coa.try_loading_for_current_company() diff --git a/odoo/addons/base/models/ir_module.py b/odoo/addons/base/models/ir_module.py index 1afe44bb05c..cd48963b253 100644 --- a/odoo/addons/base/models/ir_module.py +++ b/odoo/addons/base/models/ir_module.py @@ -445,7 +445,8 @@ class Module(models.Model): # allowed companies to configure it on the correct company. # Otherwise, the SUPERUSER won't be aware of that and will try to # configure the CoA on his own company, which makes no sense. - request.allowed_company_ids = self.env.company_ids.ids + if request: + request.allowed_company_ids = self.env.company_ids.ids return self._button_immediate_function(type(self).button_install) @assert_log_admin_access