From 42e278840e82408cbb67c7b541d0b9cb736c3f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20L=C3=B3pez=20Pe=C3=B1alver?= Date: Fri, 19 Apr 2024 09:23:56 +0200 Subject: [PATCH] [16.0][MIG] l10n_ue_nace PR upgrades --- l10n_eu_nace/README.rst | 7 +-- l10n_eu_nace/__manifest__.py | 1 - l10n_eu_nace/i18n/es.po | 27 ++++++++++- l10n_eu_nace/readme/USAGE.rst | 5 +- l10n_eu_nace/static/description/index.html | 7 +-- .../tests/test_en_nace_request_results.py | 24 +++++----- ...est_res_partner_industry_eu_nace_wizard.py | 19 +++----- .../res_partner_industry_eu_nace_wizard.py | 47 ++++++++++++------- ...s_partner_industry_eu_nace_wizard_view.xml | 29 ++++++++---- requirements.txt | 3 +- 10 files changed, 106 insertions(+), 63 deletions(-) diff --git a/l10n_eu_nace/README.rst b/l10n_eu_nace/README.rst index f92d4b3e..7cbd9a13 100644 --- a/l10n_eu_nace/README.rst +++ b/l10n_eu_nace/README.rst @@ -7,7 +7,7 @@ European NACE partner categories !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:b852bc1153e9c44a78d4f09753769e4475293f75e4bbecb50791457e72342531 + !! source digest: sha256:9f77d1967af0b73295197a5b1c09c525d8a7087663e15203cbb50be777e11ea5 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -60,9 +60,10 @@ uses SPARQL to retrieve the data. If you want to import or update the data, you can do so by running the Import NACE Wizard. This will search for all active languages in Odoo and import the -data for each one. +data for each one. If you activate a new language, remember to run this wizard +again. -1. Go to "Contacts" > "Configuration" > "Import NACE Wizard" +1. Go to "Contacts" > "Configuration" > "Import NACE industries" 2. Click on the "Import NACE" button. This might take a minute or so depending on the number of languages and the diff --git a/l10n_eu_nace/__manifest__.py b/l10n_eu_nace/__manifest__.py index 78ab5227..9b1b352d 100644 --- a/l10n_eu_nace/__manifest__.py +++ b/l10n_eu_nace/__manifest__.py @@ -16,7 +16,6 @@ ], "maintainers": ["rafaelbn", "yajo", "edlopen"], "depends": ["partner_industry_secondary"], - "external_dependencies": {"python": ["requests"]}, "installable": True, "license": "AGPL-3", } diff --git a/l10n_eu_nace/i18n/es.po b/l10n_eu_nace/i18n/es.po index 0677e791..ddb41d93 100644 --- a/l10n_eu_nace/i18n/es.po +++ b/l10n_eu_nace/i18n/es.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 16.0+e\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-15 16:10+0000\n" -"PO-Revision-Date: 2024-04-15 18:10+0200\n" +"POT-Creation-Date: 2024-04-19 08:51+0000\n" +"PO-Revision-Date: 2024-04-19 10:53+0200\n" "Last-Translator: Eduardo López \n" "Language-Team: \n" "Language: es\n" @@ -17,6 +17,11 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 3.4.2\n" +#. module: l10n_eu_nace +#: model_terms:ir.ui.view,arch_db:l10n_eu_nace.partner_industry_nace_wizard_view_form +msgid "Cancel" +msgstr "" + #. module: l10n_eu_nace #: model:ir.model.fields,field_description:l10n_eu_nace.field_res_partner_industry_eu_nace_wizard__create_uid msgid "Created by" @@ -44,6 +49,17 @@ msgstr "" msgid "Import NACE industries" msgstr "Importar industrias NACE" +#. module: l10n_eu_nace +#: model_terms:ir.ui.view,arch_db:l10n_eu_nace.partner_industry_nace_wizard_view_form +msgid "" +"Import NACE industries from ShowVoc API. This will\n" +" create new industries or update existing ones with their\n" +" translations for all active languages in the system." +msgstr "" +"Importar industrias NACE del ShowVoc API. Esto\n" +" creará nuevas industrias o actualizará aquéllas con su\n" +" traducción para todos los idiomas activos en el sistema." + #. module: l10n_eu_nace #: model:ir.model.fields,field_description:l10n_eu_nace.field_res_partner_industry_eu_nace_wizard____last_update msgid "Last Modified on" @@ -59,6 +75,13 @@ msgstr "" msgid "Last Updated on" msgstr "" +#. module: l10n_eu_nace +#. odoo-python +#: code:addons/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard.py:0 +#, python-format +msgid "Partner Industries by EU NACE" +msgstr "" + #. module: l10n_eu_nace #: model:ir.model,name:l10n_eu_nace.model_res_partner_industry_eu_nace_wizard msgid "Partner Industry by EU NACE Wizard" diff --git a/l10n_eu_nace/readme/USAGE.rst b/l10n_eu_nace/readme/USAGE.rst index 156408f5..cca62b38 100644 --- a/l10n_eu_nace/readme/USAGE.rst +++ b/l10n_eu_nace/readme/USAGE.rst @@ -9,9 +9,10 @@ uses SPARQL to retrieve the data. If you want to import or update the data, you can do so by running the Import NACE Wizard. This will search for all active languages in Odoo and import the -data for each one. +data for each one. If you activate a new language, remember to run this wizard +again. -1. Go to "Contacts" > "Configuration" > "Import NACE Wizard" +1. Go to "Contacts" > "Configuration" > "Import NACE industries" 2. Click on the "Import NACE" button. This might take a minute or so depending on the number of languages and the diff --git a/l10n_eu_nace/static/description/index.html b/l10n_eu_nace/static/description/index.html index d188f8bd..899865ed 100644 --- a/l10n_eu_nace/static/description/index.html +++ b/l10n_eu_nace/static/description/index.html @@ -367,7 +367,7 @@

European NACE partner categories

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:b852bc1153e9c44a78d4f09753769e4475293f75e4bbecb50791457e72342531 +!! source digest: sha256:9f77d1967af0b73295197a5b1c09c525d8a7087663e15203cbb50be777e11ea5 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/community-data-files Translate me on Weblate Try me on Runboat

This module imports the NACE rev. 2 classification @@ -406,9 +406,10 @@

Obtaining updated data

uses SPARQL to retrieve the data.

If you want to import or update the data, you can do so by running the Import NACE Wizard. This will search for all active languages in Odoo and import the -data for each one.

+data for each one. If you activate a new language, remember to run this wizard +again.

    -
  1. Go to “Contacts” > “Configuration” > “Import NACE Wizard”
  2. +
  3. Go to “Contacts” > “Configuration” > “Import NACE industries”
  4. Click on the “Import NACE” button.

This might take a minute or so depending on the number of languages and the diff --git a/l10n_eu_nace/tests/test_en_nace_request_results.py b/l10n_eu_nace/tests/test_en_nace_request_results.py index 2ac9f39f..9e665d08 100644 --- a/l10n_eu_nace/tests/test_en_nace_request_results.py +++ b/l10n_eu_nace/tests/test_en_nace_request_results.py @@ -67,22 +67,22 @@ { "ES": { "type": "literal", - "value": "01 Agricultura, ganadería, caza y servicios relacionados\ + "value": "Agricultura, ganadería, caza y servicios relacionados\ con las mismas", } }, - {"ES": {"type": "literal", "value": "01.1 Cultivos no perennes"}}, + {"ES": {"type": "literal", "value": "Cultivos no perennes"}}, { "ES": { "type": "literal", - "value": "01.11 Cultivo de cereales (excepto arroz), \ + "value": "Cultivo de cereales (excepto arroz), \ leguminosas y semillas oleaginosas", } }, { "ES": { "type": "literal", - "value": "02 Silvicultura y explotación \ + "value": "Silvicultura y explotación \ forestal", } }, @@ -92,41 +92,41 @@ { "EN": { "type": "literal", - "value": "01 Crop and animal production, hunting and related \ + "value": "Crop and animal production, hunting and related \ service activities", } }, - {"EN": {"type": "literal", "value": "01.1 Growing of non-perennial crops"}}, + {"EN": {"type": "literal", "value": "Growing of non-perennial crops"}}, { "EN": { "type": "literal", - "value": "01.11 Growing of cereals (except rice), leguminous crops \ + "value": "Growing of cereals (except rice), leguminous crops \ and oil seeds", } }, - {"EN": {"type": "literal", "value": "02 Forestry and logging"}}, + {"EN": {"type": "literal", "value": "Forestry and logging"}}, ] NACE_FR = [ { "FR": { "type": "literal", - "value": "01 Culture et production animale, chasse et services \ + "value": "Culture et production animale, chasse et services \ annexes", } }, - {"FR": {"type": "literal", "value": "01.1 Cultures non permanentes"}}, + {"FR": {"type": "literal", "value": "Cultures non permanentes"}}, { "FR": { "type": "literal", - "value": "01.11 Culture de céréales (à l'exception du riz), de \ + "value": "Culture de céréales (à l'exception du riz), de \ légumineuses et de graines oléagineuses", } }, { "FR": { "type": "literal", - "value": "02 Sylviculture et exploitation \ + "value": "Sylviculture et exploitation \ forestière", } }, diff --git a/l10n_eu_nace/tests/test_res_partner_industry_eu_nace_wizard.py b/l10n_eu_nace/tests/test_res_partner_industry_eu_nace_wizard.py index 7f1a3fae..3e3751b8 100644 --- a/l10n_eu_nace/tests/test_res_partner_industry_eu_nace_wizard.py +++ b/l10n_eu_nace/tests/test_res_partner_industry_eu_nace_wizard.py @@ -2,7 +2,7 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). from unittest.mock import patch -from odoo.tests.common import Form, TransactionCase, new_test_user, users +from odoo.tests.common import Form, TransactionCase, new_test_user from .test_en_nace_request_results import ( NACE_COMMON, @@ -21,7 +21,7 @@ class TestResPartnerIndustryEUNaceWizard(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.user = new_test_user( + cls.uid = new_test_user( cls.env, login="test-manager", groups="base.group_system", @@ -36,12 +36,11 @@ def activate_langs(self, lang_list): def wizard_eu_nace(self): wizard = Form( - self.env["res.partner.industry.eu.nace.wizard"].with_user(self.user) + self.env["res.partner.industry.eu.nace.wizard"].with_user(self.uid) ) import_wizard = wizard.save() return import_wizard - @users("test-manager") def test_get_languages(self): nace_wizard = self.wizard_eu_nace() self.assertEqual(nace_wizard.get_languages(), [("en_US", "EN")]) @@ -68,7 +67,6 @@ def test_get_languages(self): expected = [("en_US", "EN"), ("es_ES", "ES"), ("my_MM", "EN")] self.assertCountEqual(nace_wizard.get_languages(), expected) - @users("test-manager") def test_create_query(self): nace_wizard = self.wizard_eu_nace() active_languages = ["base.lang_en", "base.lang_es", "base.lang_fr"] @@ -79,9 +77,9 @@ def test_create_query(self): self.assertIn("?ES", query) self.assertIn("?FR", query) self.assertIn("?FR", query) - self.assertIn("skos:prefLabel ?LabelES;", query) - self.assertIn("skos:prefLabel ?LabelEN;", query) - self.assertIn("skos:prefLabel ?LabelFR;", query) + self.assertIn("skos:altLabel ?LabelES;", query) + self.assertIn("skos:altLabel ?LabelEN;", query) + self.assertIn("skos:altLabel ?LabelFR;", query) self.assertIn('FILTER (LANG(?LabelES) = "es")', query) self.assertIn("BIND (STR(?LabelES) as ?ES)", query) self.assertIn('FILTER (LANG(?LabelEN) = "en")', query) @@ -89,7 +87,6 @@ def test_create_query(self): self.assertIn('FILTER (LANG(?LabelFR) = "fr")', query) self.assertIn("BIND (STR(?LabelFR) as ?FR)", query) - @users("test-manager") @patch(MOCK_PATH, return_value=create_response(NACE_COMMON, NACE_EN)) def test_update_partner_industry_eu_nace_english_only(self, mock_request): self.activate_langs(["base.lang_en"]) @@ -97,7 +94,6 @@ def test_update_partner_industry_eu_nace_english_only(self, mock_request): records_created = nace_wizard.update_partner_industry_eu_nace() self.assertEqual(len(records_created), 4) - @users("test-manager") @patch( MOCK_PATH, return_value=create_response(NACE_COMMON, NACE_EN, NACE_ES, NACE_FR) ) @@ -110,7 +106,6 @@ def test_update_partner_industry_eu_nace_multiple_languages_with_english( records_created = nace_wizard.update_partner_industry_eu_nace() self.assertEqual(len(records_created), 4) - @users("test-manager") @patch( MOCK_PATH, return_value=create_response(NACE_COMMON, NACE_EN, NACE_ES, NACE_FR) ) @@ -120,7 +115,6 @@ def test_update_partner_industry_eu_nace_no_english(self, mock_request): records_created = nace_wizard.update_partner_industry_eu_nace() self.assertEqual(len(records_created), 4) - @users("test-manager") @patch(MOCK_PATH, return_value=create_response(NACE_COMMON, NACE_EN, NACE_ES)) def test_update_partner_industry_eu_nace_new_language_update(self, mock_request): self.activate_langs(["base.lang_en", "base.lang_es"]) @@ -139,7 +133,6 @@ def test_update_partner_industry_eu_nace_new_language_update(self, mock_request) nace_fr_names = list(map(lambda item: item.get("FR").get("value"), NACE_FR)) self.assertCountEqual(records_created_name_fr, nace_fr_names) - @users("test-manager") @patch(MOCK_PATH, return_value=create_response(NACE_COMMON, NACE_EN, NACE_ES)) def test_update_partner_industry_eu_nace_idempotent_update(self, mock_request): self.activate_langs(["base.lang_en"]) diff --git a/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard.py b/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard.py index fb193bee..1378c231 100644 --- a/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard.py +++ b/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard.py @@ -3,7 +3,7 @@ import requests -from odoo import models +from odoo import _, models ENDPOINT = "https://publications.europa.eu/webapi/rdf/sparql" # List of languages imported in previous versions of the module. @@ -75,7 +75,7 @@ def get_select_query(language): @staticmethod def get_skos_query(language): - return f"skos:prefLabel ?Label{language};" + return f"skos:altLabel ?Label{language};" @staticmethod def get_filter_query(language): @@ -133,7 +133,8 @@ def _create_query(self, language_list): BIND (STRAFTER(?NACELEVEL, "/nace2/") AS ?LEVEL) ?Member skos:prefLabel ?MemberLabel . FILTER (LANG(?MemberLabel) = "en") - }} ORDER BY ?code + BIND (xsd:integer(REPLACE(?code, "\\D", "")) AS ?code_formatted) + }} ORDER BY ?code_formatted """ return query @@ -143,31 +144,33 @@ def _create_nace_industry(self, nace_data, languages): nace_ids = self.env["res.partner.industry"] nace_json = nace_data.json() bindings = nace_json.get("results", {}).get("bindings", {}) + all_naces = nace_ids.search_read([], ["full_name"]) + nace_map = { + nace.get("full_name").split(" - ")[0]: nace.get("id") for nace in all_naces + } for binding in bindings: nace_code = binding.get("code", {}).get("value", "") - nace_id = self.env["res.partner.industry"].search( - [("full_name", "=like", nace_code + "%")], limit=1 - ) + nace_id = nace_map.get(nace_code, False) nace_parent_code = binding.get("parentCode", {}).get("value", "") - parent_id = self.env["res.partner.industry"].search( - [("full_name", "=like", nace_parent_code + "%")], limit=1 - ) + parent_id = nace_map.get(nace_parent_code, False) nace_name = binding.get("EN", {}).get("value") if not nace_id: - nace_id = self.env["res.partner.industry"].create( + nace = self.env["res.partner.industry"].create( { "name": nace_name, - "full_name": nace_name, - "parent_id": parent_id and parent_id.id, + "full_name": f"{nace_code} - {nace_name}", + "parent_id": parent_id, } ) - nace_ids |= nace_id + nace_map[nace_code] = nace.id + nace_ids |= nace for lang, lang_code in languages: nace_translated = binding.get(lang_code, {}).get("value") - nace_id.with_context(lang=lang).write( + nace = nace_ids.browse(nace_map[nace_code]) + nace.with_context(lang=lang).write( { "name": nace_translated, - "full_name": nace_translated, + "full_name": f"{nace_code} - {nace_translated}", } ) return nace_ids @@ -176,8 +179,20 @@ def update_partner_industry_eu_nace(self): languages = self.get_languages() query = self._create_query(languages) result = requests.get( - ENDPOINT, params={"format": "json", "query": query}, timeout=60 + ENDPOINT, params={"format": "json", "query": query}, timeout=120 ) result.raise_for_status() nace_ids = self._create_nace_industry(result, languages) return nace_ids + + def action_partner_industry_eu_nace(self): + self.update_partner_industry_eu_nace() + tree_view_id = self.env.ref("base.res_partner_industry_view_tree").id + return { + "name": _("Partner Industries by EU NACE"), + "view_mode": "tree", + "res_model": "res.partner.industry", + "view_id": tree_view_id, + "type": "ir.actions.act_window", + "domain": [], + } diff --git a/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard_view.xml b/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard_view.xml index 41b7cb5e..5c368329 100644 --- a/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard_view.xml +++ b/l10n_eu_nace/wizard/res_partner_industry_eu_nace_wizard_view.xml @@ -1,5 +1,5 @@ - @@ -9,15 +9,21 @@

- -