diff --git a/.travis.yml b/.travis.yml index 12862c09a..ea881ba1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ addons: env: global: - VERSION="12.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0" + - COUNTRY="US" matrix: - LINT_CHECK="1" diff --git a/company_country/README.rst b/company_country/README.rst new file mode 100644 index 000000000..7ad8e2d56 --- /dev/null +++ b/company_country/README.rst @@ -0,0 +1,114 @@ +=============== +Company Country +=============== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/12.0/company_country + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-company_country + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/149/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allow set a country to main company in order to use the hook of +account that install l10n_** based on country of main company. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +To install this module, you need to: + +#. Add as depends from your main module. + +Configuration +============= + +To configure this module, you need to: + +#. Set the environment variable COUNTRY using 2 letter of ISO 3166 codes. + +Usage +===== + +To use this module, you need to: + +#. Just start server installing your main module. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/149/12.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Vauxoo + +Contributors +~~~~~~~~~~~~ + +* Moisés López + + +Other credits +~~~~~~~~~~~~~ + +Vauxoo + + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-moylop260| image:: https://github.com/moylop260.png?size=40px + :target: https://github.com/moylop260 + :alt: moylop260 + +Current `maintainer `__: + +|maintainer-moylop260| + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/company_country/__init__.py b/company_country/__init__.py new file mode 100644 index 000000000..6b897e75a --- /dev/null +++ b/company_country/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2016 Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import models +from . import tests diff --git a/company_country/__manifest__.py b/company_country/__manifest__.py new file mode 100644 index 000000000..fad56b085 --- /dev/null +++ b/company_country/__manifest__.py @@ -0,0 +1,17 @@ +# © 2016 Vauxoo () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Company Country", + "summary": "Set country to main company", + "version": "12.0.1.0.0", + "category": "base", + "website": "https://github.com/OCA/server-tools/tree/12.0/company_country", + "maintainers": ['moylop260'], + "author": "Vauxoo, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [], + "data": ['data/res_config.xml'], + "sequence": 1, + "auto_install": False, + "installable": True, +} diff --git a/company_country/data/res_config.xml b/company_country/data/res_config.xml new file mode 100644 index 000000000..4ab12532b --- /dev/null +++ b/company_country/data/res_config.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/company_country/models/__init__.py b/company_country/models/__init__.py new file mode 100644 index 000000000..3d901f57a --- /dev/null +++ b/company_country/models/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2016 Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import res_config diff --git a/company_country/models/res_config.py b/company_country/models/res_config.py new file mode 100644 index 000000000..ab2721234 --- /dev/null +++ b/company_country/models/res_config.py @@ -0,0 +1,35 @@ +# Copyright 2016 Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import os + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class CompanyCountryConfigSettings(models.TransientModel): + _name = 'company.country.config.settings' + _description = 'Company Country Configuration Settings' + + @api.model + def load_company_country(self, country_code=None): + if not country_code: + country_code = os.environ.get('COUNTRY') + if country_code == "": + self.env.ref('base.main_company').write({'country_id': None}) + return + if not country_code: + l10n_to_install = self.env['ir.module.module'].search([ + ('state', '=', 'to install'), + ('name', '=like', 'l10n_%')], limit=1) + if not l10n_to_install: + raise ValidationError( + _('Error COUNTRY environment variable with country code ' + 'not defined and no localization found in pool.')) + country_code = l10n_to_install.name.split('l10n_')[1][:2].upper() + + country = self.env['res.country'].search([ + ('code', 'ilike', country_code)], limit=1) + if not country: + raise ValidationError( + _('Country code %s not found. Use ISO 3166 codes 2 letters')) + self.env.ref('base.main_company').write({'country_id': country.id}) diff --git a/company_country/readme/CONFIGURE.rst b/company_country/readme/CONFIGURE.rst new file mode 100644 index 000000000..47a61effd --- /dev/null +++ b/company_country/readme/CONFIGURE.rst @@ -0,0 +1,3 @@ +To configure this module, you need to: + +#. Set the environment variable COUNTRY using 2 letter of ISO 3166 codes. diff --git a/company_country/readme/CONTRIBUTORS.rst b/company_country/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..230f2b69b --- /dev/null +++ b/company_country/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Moisés López + diff --git a/company_country/readme/CREDITS.rst b/company_country/readme/CREDITS.rst new file mode 100644 index 000000000..2f99b446d --- /dev/null +++ b/company_country/readme/CREDITS.rst @@ -0,0 +1,2 @@ +Vauxoo + diff --git a/company_country/readme/DESCRIPTION.rst b/company_country/readme/DESCRIPTION.rst new file mode 100644 index 000000000..3b4985157 --- /dev/null +++ b/company_country/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allow set a country to main company in order to use the hook of +account that install l10n_** based on country of main company. diff --git a/company_country/readme/INSTALL.rst b/company_country/readme/INSTALL.rst new file mode 100644 index 000000000..8940b3f29 --- /dev/null +++ b/company_country/readme/INSTALL.rst @@ -0,0 +1,3 @@ +To install this module, you need to: + +#. Add as depends from your main module. diff --git a/company_country/readme/USAGE.rst b/company_country/readme/USAGE.rst new file mode 100644 index 000000000..6f0149c3f --- /dev/null +++ b/company_country/readme/USAGE.rst @@ -0,0 +1,7 @@ +To use this module, you need to: + +#. Just start server installing your main module. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/149/12.0 diff --git a/company_country/static/description/index.html b/company_country/static/description/index.html new file mode 100644 index 000000000..f753d6094 --- /dev/null +++ b/company_country/static/description/index.html @@ -0,0 +1,452 @@ + + + + + + +Company Country + + + +
+

Company Country

+ + +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

This module allow set a country to main company in order to use the hook of +account that install l10n_** based on country of main company.

+

Table of contents

+ +
+

Installation

+

To install this module, you need to:

+
    +
  1. Add as depends from your main module.
  2. +
+
+
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Set the environment variable COUNTRY using 2 letter of ISO 3166 codes.
  2. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Just start server installing your main module.
  2. +
+Try me on Runbot +
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Vauxoo
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

Vauxoo

+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

moylop260

+

This module is part of the OCA/server-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/company_country/tests/__init__.py b/company_country/tests/__init__.py new file mode 100644 index 000000000..88b24c12e --- /dev/null +++ b/company_country/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_company_country diff --git a/company_country/tests/test_company_country.py b/company_country/tests/test_company_country.py new file mode 100644 index 000000000..72a9f4eac --- /dev/null +++ b/company_country/tests/test_company_country.py @@ -0,0 +1,46 @@ +# Copyright 2016 Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import os + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestCompanyCountry(TransactionCase): + + def setUp(self): + super(TestCompanyCountry, self).setUp() + self.wizard = self.env['company.country.config.settings'] + 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.main_company.write({'country_id': self.us_country.id}) + self.env_country = os.environ.get('COUNTRY') + + def tearDown(self): + super(TestCompanyCountry, self).tearDown() + os.environ['COUNTRY'] = self.env_country + + def test01_company_country_changed(self): + self.wizard.load_company_country(country_code='MX') + self.assertEqual(self.main_company.country_id, self.mx_country) + + def test02_country_environment_values(self): + # Country Code unknown, should raise + with self.assertRaises(ValidationError): + self.wizard.load_company_country(country_code='BAD') + + # COUNTRY as empty string, should unset Country of main company + os.environ['COUNTRY'] = "" + self.wizard.load_company_country() + self.assertEqual(self.main_company.country_id.id, False) + + # COUNTRY environment variable not set, should raise + with self.assertRaises(ValidationError): + l10n_to_install = self.env['ir.module.module'].search([ + ('state', '=', 'to install'), + ('name', '=like', 'l10n_%')]) + l10n_to_install.write({'state': 'uninstalled'}) + del os.environ['COUNTRY'] + self.wizard.load_company_country()