diff --git a/.travis.yml b/.travis.yml index 7048b77b5..b8a0f4c79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ jobs: env: global: - VERSION="13.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0" + - COUNTRY="US" install: - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools diff --git a/company_country/README.rst b/company_country/README.rst new file mode 100644 index 000000000..5b8b730e8 --- /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/13.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-13-0/server-tools-13-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/13.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/13.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..109a2339a --- /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": "13.0.1.0.0", + "category": "base", + "website": "https://github.com/OCA/server-tools/tree/13.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/i18n/company_country.pot b/company_country/i18n/company_country.pot new file mode 100644 index 000000000..2d801cc6e --- /dev/null +++ b/company_country/i18n/company_country.pot @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * company_country +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: company_country +#: model:ir.model,name:company_country.model_company_country_config_settings +msgid "Company Country Configuration Settings" +msgstr "" + +#. module: company_country +#: code:addons/company_country/models/res_config.py:34 +#, python-format +msgid "Country code %s not found. Use ISO 3166 codes 2 letters" +msgstr "" + +#. module: company_country +#: model:ir.model.fields,field_description:company_country.field_company_country_config_settings__create_uid +msgid "Created by" +msgstr "" + +#. module: company_country +#: model:ir.model.fields,field_description:company_country.field_company_country_config_settings__create_date +msgid "Created on" +msgstr "" + +#. module: company_country +#: model:ir.model.fields,field_description:company_country.field_company_country_config_settings__display_name +msgid "Display Name" +msgstr "" + +#. module: company_country +#: code:addons/company_country/models/res_config.py:26 +#, python-format +msgid "Error COUNTRY environment variable with country code not defined and no localization found in pool." +msgstr "" + +#. module: company_country +#: model:ir.model.fields,field_description:company_country.field_company_country_config_settings__id +msgid "ID" +msgstr "" + +#. module: company_country +#: model:ir.model.fields,field_description:company_country.field_company_country_config_settings____last_update +msgid "Last Modified on" +msgstr "" + +#. module: company_country +#: model:ir.model.fields,field_description:company_country.field_company_country_config_settings__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: company_country +#: model:ir.model.fields,field_description:company_country.field_company_country_config_settings__write_date +msgid "Last Updated on" +msgstr "" + 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..7346ff350 --- /dev/null +++ b/company_country/models/res_config.py @@ -0,0 +1,40 @@ +# 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..aecc7027e --- /dev/null +++ b/company_country/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Moisés López diff --git a/company_country/readme/CREDITS.rst b/company_country/readme/CREDITS.rst new file mode 100644 index 000000000..d0ec12698 --- /dev/null +++ b/company_country/readme/CREDITS.rst @@ -0,0 +1 @@ +Vauxoo diff --git a/company_country/readme/DESCRIPTION.rst b/company_country/readme/DESCRIPTION.rst new file mode 100644 index 000000000..09aa697f9 --- /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..cb3673b3c --- /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/13.0 diff --git a/company_country/static/description/icon.png b/company_country/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/company_country/static/description/icon.png differ diff --git a/company_country/static/description/index.html b/company_country/static/description/index.html new file mode 100644 index 000000000..21a70a48a --- /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..0ac2d0fee --- /dev/null +++ b/company_country/tests/test_company_country.py @@ -0,0 +1,53 @@ +# 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) + + def test03_conuntry_environ_not_set(self): + del os.environ["COUNTRY"] + + # COUNTRY environment not set but l10n marked to install + l10n_mx = self.env["ir.module.module"].search([("name", "=", "l10n_mx")]) + l10n_mx.write({"state": "to install"}) + self.wizard.load_company_country() + self.assertEqual(self.main_company.country_id, self.mx_country) + + # 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"}) + self.wizard.load_company_country()