From de012e42835c765a4246e1f77759d1e3370bb07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Gonz=C3=A1lez=20=5BVauxoo=5D?= Date: Mon, 16 Mar 2020 13:44:28 -0600 Subject: [PATCH] [FIX] company_country: Don't fail if account is already installed (#1786) * [FIX] company_country: Don't fail if account is already installed When `company_country` is installed, it performs the following: - Look for the `COUNTRY` environment variable - If not found, look for a `l10n_*` module that is about to be installed - If not found, raise an exception However, If the account module is installed, it shouldn't fail even if the environment variable is not defined, because changing the company's country will have no effect anyway, as the account hook was already run and an `l10n` module was already been installed. This commit fixes the above by skipping the process if the `account` module is installed, and print an informative message to the log. * Update __manifest__.py Co-authored-by: Moises Lopez - https://www.vauxoo.com/ --- company_country/README.rst | 1 + company_country/__manifest__.py | 4 ++-- company_country/models/res_config.py | 15 ++++++++++++++- company_country/tests/test_company_country.py | 6 ++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/company_country/README.rst b/company_country/README.rst index 7ad8e2d56..6458447ee 100644 --- a/company_country/README.rst +++ b/company_country/README.rst @@ -80,6 +80,7 @@ Contributors ~~~~~~~~~~~~ * Moisés López +* Luis González Other credits diff --git a/company_country/__manifest__.py b/company_country/__manifest__.py index fad56b085..a767139d1 100644 --- a/company_country/__manifest__.py +++ b/company_country/__manifest__.py @@ -3,10 +3,10 @@ { "name": "Company Country", "summary": "Set country to main company", - "version": "12.0.1.0.0", + "version": "12.0.1.0.1", "category": "base", "website": "https://github.com/OCA/server-tools/tree/12.0/company_country", - "maintainers": ['moylop260'], + "maintainers": ['moylop260', 'luisg123v'], "author": "Vauxoo, Odoo Community Association (OCA)", "license": "AGPL-3", "depends": [], diff --git a/company_country/models/res_config.py b/company_country/models/res_config.py index ab2721234..18970e5a4 100644 --- a/company_country/models/res_config.py +++ b/company_country/models/res_config.py @@ -1,10 +1,13 @@ # Copyright 2016 Vauxoo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import logging import os from odoo import _, api, models from odoo.exceptions import ValidationError +_logger = logging.getLogger(__name__) + class CompanyCountryConfigSettings(models.TransientModel): _name = 'company.country.config.settings' @@ -12,10 +15,20 @@ class CompanyCountryConfigSettings(models.TransientModel): @api.model def load_company_country(self, country_code=None): + account_installed = self.env['ir.module.module'].search([ + ('name', '=', 'account'), + ('state', '=', 'installed'), + ], limit=1) + if account_installed: + # If the account module is installed, that means changing the + # company's country will have no effect, as the account hook was + # already run and an l10n module was already been installed + _logger.info("account module already installed, skipping") + return if not country_code: country_code = os.environ.get('COUNTRY') if country_code == "": - self.env.ref('base.main_company').write({'country_id': None}) + self.env.ref('base.main_company').write({'country_id': False}) return if not country_code: l10n_to_install = self.env['ir.module.module'].search([ diff --git a/company_country/tests/test_company_country.py b/company_country/tests/test_company_country.py index 72a9f4eac..29a0478f0 100644 --- a/company_country/tests/test_company_country.py +++ b/company_country/tests/test_company_country.py @@ -15,7 +15,9 @@ class TestCompanyCountry(TransactionCase): self.us_country = self.env.ref('base.us') self.mx_country = self.env.ref('base.mx') self.main_company = self.env.ref('base.main_company') + self.module_account = self.env.ref('base.module_account') self.main_company.write({'country_id': self.us_country.id}) + self.module_account.write({'state': 'uninstalled'}) self.env_country = os.environ.get('COUNTRY') def tearDown(self): @@ -44,3 +46,7 @@ class TestCompanyCountry(TransactionCase): l10n_to_install.write({'state': 'uninstalled'}) del os.environ['COUNTRY'] self.wizard.load_company_country() + + # Account is already installed, shouldn't raise + self.module_account.write({'state': 'installed'}) + self.wizard.load_company_country()