diff --git a/l10n_fr_state/README.rst b/l10n_fr_state/README.rst new file mode 100644 index 000000000..f23c9863f --- /dev/null +++ b/l10n_fr_state/README.rst @@ -0,0 +1,106 @@ +======================= +French States (Régions) +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:573c0598b59f23178241b44edcc301b488a34eaa0f0eb6d9e839e4c29612101a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fl10n--france-lightgray.png?logo=github + :target: https://github.com/OCA/l10n-france/tree/18.0/l10n_fr_state + :alt: OCA/l10n-france +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/l10n-france-18-0/l10n-france-18-0-l10n_fr_state + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-france&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module populate the table *res_country_state* with the french +states (*Régions françaises*), but only the french states of mainland. +If you need the overseas states, please install the module +*l10n_fr_department_oversea*. + +In the past, the module was using 3166-2:FR codifications without +country prefix (more detail on +`Wikipedia `__), but +unfortunately this codification hasn't been updated since 2013, so we +can't use it with the new organisation of regions that was introduced on +January 1st 2016. So we switched to the INSEE codification, cf +`Wikipedia +(Codes_géographiques_de_la_France) `__ +; by the way, this codification is also used by +`geonames.org `__. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* GRAP +* Akretion +* Nicolas JEUDY + +Contributors +------------ + +- Sylvain LE GAL (`Twitter `__), GRAP + (Groupement Régional Alimentaire de Proximité) +- Alexis de Lattre +- Nicolas JEUDY + +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-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain +.. |maintainer-alexis-via| image:: https://github.com/alexis-via.png?size=40px + :target: https://github.com/alexis-via + :alt: alexis-via + +Current `maintainers `__: + +|maintainer-legalsylvain| |maintainer-alexis-via| + +This module is part of the `OCA/l10n-france `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/l10n_fr_state/__init__.py b/l10n_fr_state/__init__.py new file mode 100644 index 000000000..c36b9b9c6 --- /dev/null +++ b/l10n_fr_state/__init__.py @@ -0,0 +1 @@ +from .pre_init_hook import create_fr_state_xmlid diff --git a/l10n_fr_state/__manifest__.py b/l10n_fr_state/__manifest__.py new file mode 100644 index 000000000..abf9ae973 --- /dev/null +++ b/l10n_fr_state/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2013-2022 GRAP (Sylvain LE GAL https://twitter.com/legalsylvain) +# Copyright 2015-2022 Akretion France +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "French States (Régions)", + "summary": "Populate Database with French States (Régions)", + "version": "18.0.1.0.0", + "category": "French Localization", + "author": "GRAP, " + "Akretion, " + "Nicolas JEUDY, " + "Odoo Community Association (OCA)", + "maintainers": ["legalsylvain", "alexis-via"], + "website": "https://github.com/OCA/l10n-france", + "license": "AGPL-3", + "depends": ["base"], + "pre_init_hook": "create_fr_state_xmlid", + "data": ["data/res_country_state.xml"], + "images": ["static/src/img/screenshots/1.png"], + "installable": True, +} diff --git a/l10n_fr_state/data/res_country_state.xml b/l10n_fr_state/data/res_country_state.xml new file mode 100644 index 000000000..c783d8228 --- /dev/null +++ b/l10n_fr_state/data/res_country_state.xml @@ -0,0 +1,78 @@ + + + + + + Grand Est + 44 + + + + + Nouvelle-Aquitaine + 75 + + + + Auvergne-Rhône-Alpes + 84 + + + + Bourgogne-Franche-Comté + 27 + + + + Bretagne + 53 + + + + Centre-Val de Loire + 24 + + + + Corse + 94 + + + + Île-de-France + 11 + + + + + Occitanie + 76 + + + + + Hauts-de-France + 32 + + + + Normandie + 28 + + + + Pays de la Loire + 52 + + + + Provence-Alpes-Côte d'Azur + 93 + + + diff --git a/l10n_fr_state/i18n/fr.po b/l10n_fr_state/i18n/fr.po new file mode 100644 index 000000000..c3b89b0c1 --- /dev/null +++ b/l10n_fr_state/i18n/fr.po @@ -0,0 +1,102 @@ +# ############################################################################# +# +# l10n FR States module for OpenERP +# Copyright (C) 2013-2014 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# ############################################################################# +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * l10n_fr_state +# * base +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-03-26 16:08+0000\n" +"PO-Revision-Date: 2014-03-26 16:08+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#~ msgid "Country state" +#~ msgstr "Région" + +#~ msgid "State Name" +#~ msgstr "Nom de la région" + +#~ msgid "State Code" +#~ msgstr "Code de la région" + +#~ msgid "French States (Région)" +#~ msgstr "Régions Françaises" + +#~ msgid "Populate Database with French States (Région)" +#~ msgstr "Remplit la base de données avec les régions françaises" + +#~ msgid "" +#~ "\n" +#~ "Populate Database with French States (Région)\n" +#~ "=============================================\n" +#~ "\n" +#~ "Feature:\n" +#~ "--------\n" +#~ " * Populate the table res_country_state with the french states. (named " +#~ "'Région')\n" +#~ "\n" +#~ "Technical information:\n" +#~ "----------------------\n" +#~ " * Use 3166-2:FR codifications (more detail http://fr.wikipedia.org/" +#~ "wiki/ISO_3166-2:FR);\n" +#~ " * Only populate inner states; (no Guyane, Mayotte, etc...) because " +#~ "there are in the res_country table;\n" +#~ " * Change res_country_state.code size. (3 to 4);\n" +#~ "\n" +#~ "Copyright, Authors and Licence:\n" +#~ "-------------------------------\n" +#~ " * Copyright: 2013-2014, GRAP, Groupement Régional Alimentaire de " +#~ "Proximité;\n" +#~ " * Author: Sylvain LE GAL (https://twitter.com/legalsylvain);\n" +#~ " * Licence: AGPL-3 (http://www.gnu.org/licenses/);" +#~ msgstr "" +#~ "\n" +#~ "Remplit la base de données avec les régions françaises\n" +#~ "======================================================\n" +#~ "\n" +#~ "Caractéristique :\n" +#~ "-----------------\n" +#~ " * Remplit la table 'res_country_state' avec les régions françaises\n" +#~ "\n" +#~ "Informations techniques :\n" +#~ "-------------------------\n" +#~ " * Utilise la codification 3166-2:FR (plus de détail sur http://fr." +#~ "wikipedia.org/wiki/ISO_3166-2:FR) ;\n" +#~ " * Ne remplit que les régions métropolitaines (pas la Guyane, ni " +#~ "Mayotte, etc...) car ces régions sont déjà présentes dans la table " +#~ "'res_country' ;\n" +#~ " * Modifie la taille du champs 'res_country_state.code'. (de 3 à 4 " +#~ "caractères) ;\n" +#~ "\n" +#~ "Copyright, Auteurs et Licence:\n" +#~ "------------------------------\n" +#~ " * Copyright : 2013, Groupement Régional Alimentaire de Proximité ;\n" +#~ " * Auteur : Sylvain LE GAL (https://twitter.com/legalsylvain) ;\n" +#~ " * Licence : AGPL-3 (http://www.gnu.org/licenses/) ;" diff --git a/l10n_fr_state/i18n/l10n_fr_state.pot b/l10n_fr_state/i18n/l10n_fr_state.pot new file mode 100644 index 000000000..716a0702d --- /dev/null +++ b/l10n_fr_state/i18n/l10n_fr_state.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.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" diff --git a/l10n_fr_state/pre_init_hook.py b/l10n_fr_state/pre_init_hook.py new file mode 100644 index 000000000..fe545590b --- /dev/null +++ b/l10n_fr_state/pre_init_hook.py @@ -0,0 +1,60 @@ +# Copyright 2017-2022 Akretion France +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import logging + +from lxml import etree + +from odoo.tools import file_open + +logger = logging.getLogger(__name__) + +# This code is designed to avoid a problem in the following scenario: +# On a new database, the administrator executes these steps in this order: +# 1) installs base_address_extended_geonames_import and run the geonames import wizard +# for France +# -> it creates all the French regions (without xmlid) +# 2) installs l10n_fr_state +# -> it tries to create the French regions, but it fails due to the unicity +# constraint unique(country_id, code) of res.country.state. + + +def create_fr_state_xmlid(env): + generic_create_state_xmlid(env, "l10n_fr_state", "data/res_country_state.xml") + + +def generic_create_state_xmlid(env, module_name, data_file): + """This method is also used by l10n_fr_state and l10n_fr_department_oversea""" + with file_open(f"{module_name}/{data_file}", "rb") as f: + xml_root = etree.parse(f) + data = {} # key = xmlid, value = {"code": "GP", "country_id": "base.gp"} + for record in xml_root.xpath("//record"): + xmlid = record.attrib["id"] + data[xmlid] = {} + for xfield in record.xpath("field"): + xfield_dict = xfield.attrib + data[xmlid][xfield_dict["name"]] = xfield_dict.get("ref") or xfield.text + logger.debug("generic_create_state_xmlid data=%s", data) + for xmlid, state_data in data.items(): + country_id = env.ref(state_data["country_id"]).id + state = env["res.country.state"].search( + [("code", "=", state_data["code"]), ("country_id", "=", country_id)], + limit=1, + ) + if state: + env["ir.model.data"].create( + { + "name": xmlid, + "res_id": state.id, + "module": module_name, + "model": "res.country.state", + } + ) + logger.info( + "XMLID %s.%s created for state %s code %s", + module_name, + xmlid, + state.name, + state.code, + ) diff --git a/l10n_fr_state/pyproject.toml b/l10n_fr_state/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/l10n_fr_state/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/l10n_fr_state/readme/CONTRIBUTORS.md b/l10n_fr_state/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..c9fdc52df --- /dev/null +++ b/l10n_fr_state/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Sylvain LE GAL ([Twitter](https://twitter.com/legalsylvain)), GRAP + (Groupement Régional Alimentaire de Proximité) +- Alexis de Lattre \<\> +- Nicolas JEUDY \<\> diff --git a/l10n_fr_state/readme/DESCRIPTION.md b/l10n_fr_state/readme/DESCRIPTION.md new file mode 100644 index 000000000..c1d049ca2 --- /dev/null +++ b/l10n_fr_state/readme/DESCRIPTION.md @@ -0,0 +1,15 @@ +This module populate the table *res_country_state* with the french +states (*Régions françaises*), but only the french states of mainland. +If you need the overseas states, please install the module +*l10n_fr_department_oversea*. + +In the past, the module was using 3166-2:FR codifications without +country prefix (more detail on +[Wikipedia](http://fr.wikipedia.org/wiki/ISO_3166-2:FR)), but +unfortunately this codification hasn't been updated since 2013, so we +can't use it with the new organisation of regions that was introduced on +January 1st 2016. So we switched to the INSEE codification, cf +[Wikipedia +(Codes_géographiques_de_la_France)](https://fr.wikipedia.org/wiki/Codes_g%C3%A9ographiques_de_la_France) +; by the way, this codification is also used by +[geonames.org](http://www.geonames.org/). diff --git a/l10n_fr_state/static/description/icon.png b/l10n_fr_state/static/description/icon.png new file mode 100644 index 000000000..805f2cb42 Binary files /dev/null and b/l10n_fr_state/static/description/icon.png differ diff --git a/l10n_fr_state/static/description/index.html b/l10n_fr_state/static/description/index.html new file mode 100644 index 000000000..ab889a02e --- /dev/null +++ b/l10n_fr_state/static/description/index.html @@ -0,0 +1,443 @@ + + + + + +French States (Régions) + + + +
+

French States (Régions)

+ + +

Beta License: AGPL-3 OCA/l10n-france Translate me on Weblate Try me on Runboat

+

This module populate the table res_country_state with the french +states (Régions françaises), but only the french states of mainland. +If you need the overseas states, please install the module +l10n_fr_department_oversea.

+

In the past, the module was using 3166-2:FR codifications without +country prefix (more detail on +Wikipedia), but +unfortunately this codification hasn’t been updated since 2013, so we +can’t use it with the new organisation of regions that was introduced on +January 1st 2016. So we switched to the INSEE codification, cf +Wikipedia +(Codes_géographiques_de_la_France) +; by the way, this codification is also used by +geonames.org.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • GRAP
  • +
  • Akretion
  • +
  • Nicolas JEUDY
  • +
+
+
+

Contributors

+ +
+
+

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 maintainers:

+

legalsylvain alexis-via

+

This module is part of the OCA/l10n-france project on GitHub.

+

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

+
+
+
+ + diff --git a/l10n_fr_state/static/src/img/screenshots/1.png b/l10n_fr_state/static/src/img/screenshots/1.png new file mode 100644 index 000000000..94e252eaf Binary files /dev/null and b/l10n_fr_state/static/src/img/screenshots/1.png differ