Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] company_country: improve how we process country code #142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions company_country/README.rst
Expand Up @@ -23,6 +23,17 @@ To configure this module, you need to:

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

Odoo-sh
=======

In case you need to configure odoo-sh:

- Go to your project
- Under settings go to **Module installation**
- Write down the modules you want to install, but make sure the localization is in that line along with the module you want to install

.. image:: https://user-images.githubusercontent.com/4094256/45762860-ef89cd00-bbf4-11e8-9902-9421b4163e81.png

Usage
=====

Expand Down
12 changes: 9 additions & 3 deletions company_country/models/res_config.py
Expand Up @@ -18,9 +18,15 @@ def load_country_company(self, country_code=None):
self.env.ref('base.main_company').write({'country_id': None})
return
if not country_code:
raise ValidationError(
_('Error COUNTRY environment variable with country code'
' not defined'))
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:
Expand Down