From 9d9eac31ac0ffc9a99605ac72af35bc8a3dff251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=C3=B4i=20=28Ki=C3=AAn=20Kim=29?= Date: Tue, 8 Oct 2024 17:36:17 +0700 Subject: [PATCH] [MIG] base_location_geonames_import: Migration to 18.0 --- base_location_geonames_import/README.rst | 9 ++++++++ base_location_geonames_import/__manifest__.py | 2 +- .../readme/CONTRIBUTORS.md | 1 + .../readme/CREDITS.md | 3 +++ .../static/description/index.html | 14 +++++++++-- .../wizard/geonames_import.py | 23 ++++++++++--------- .../wizard/geonames_import_view.xml | 6 ++--- 7 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 base_location_geonames_import/readme/CREDITS.md diff --git a/base_location_geonames_import/README.rst b/base_location_geonames_import/README.rst index 110d8dcb916..0b5284b7c78 100644 --- a/base_location_geonames_import/README.rst +++ b/base_location_geonames_import/README.rst @@ -89,6 +89,15 @@ Contributors - Franco Tampieri - Aitor Bouzas - Manuel Regidor +- Khoi (Kien Kim) + +Other credits +------------- + +The migration of this module from 17.0 to 18.0 was financially supported +by: + +- Camptocamp. Maintainers ----------- diff --git a/base_location_geonames_import/__manifest__.py b/base_location_geonames_import/__manifest__.py index aff71a5429a..085485d5736 100644 --- a/base_location_geonames_import/__manifest__.py +++ b/base_location_geonames_import/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Base Location Geonames Import", - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "development_status": "Mature", "category": "Partner Management", "license": "AGPL-3", diff --git a/base_location_geonames_import/readme/CONTRIBUTORS.md b/base_location_geonames_import/readme/CONTRIBUTORS.md index ec507bf4daf..de40444a873 100644 --- a/base_location_geonames_import/readme/CONTRIBUTORS.md +++ b/base_location_geonames_import/readme/CONTRIBUTORS.md @@ -6,3 +6,4 @@ - Franco Tampieri \<\> - Aitor Bouzas \<\> - Manuel Regidor \<\> +- Khoi (Kien Kim) \<\> diff --git a/base_location_geonames_import/readme/CREDITS.md b/base_location_geonames_import/readme/CREDITS.md new file mode 100644 index 00000000000..80354b7d282 --- /dev/null +++ b/base_location_geonames_import/readme/CREDITS.md @@ -0,0 +1,3 @@ +The migration of this module from 17.0 to 18.0 was financially supported by: + +- Camptocamp. diff --git a/base_location_geonames_import/static/description/index.html b/base_location_geonames_import/static/description/index.html index 67e06b78083..d81c7836d8f 100644 --- a/base_location_geonames_import/static/description/index.html +++ b/base_location_geonames_import/static/description/index.html @@ -381,7 +381,8 @@

Base Location Geonames Import

  • Credits
  • @@ -433,10 +434,19 @@

    Contributors

  • Franco Tampieri <franco@tampieri.info>
  • Aitor Bouzas <aitor.bouzas@adaptivecity.com>
  • Manuel Regidor <manuel.regidor@sygel.es>
  • +
  • Khoi (Kien Kim) <khoikk@trobz.com>
  • + + +
    +

    Other credits

    +

    The migration of this module from 17.0 to 18.0 was financially supported +by:

    +
      +
    • Camptocamp.
    -

    Maintainers

    +

    Maintainers

    This module is maintained by the OCA.

    Odoo Community Association diff --git a/base_location_geonames_import/wizard/geonames_import.py b/base_location_geonames_import/wizard/geonames_import.py index c4a4b2d9766..547c25292ed 100644 --- a/base_location_geonames_import/wizard/geonames_import.py +++ b/base_location_geonames_import/wizard/geonames_import.py @@ -15,7 +15,7 @@ import requests -from odoo import _, api, fields, models +from odoo import api, fields, models from odoo.exceptions import UserError logger = logging.getLogger(__name__) @@ -101,22 +101,23 @@ def get_and_parse_csv(self, country): "geonames.url", default="http://download.geonames.org/export/zip/%s.zip" ) url = config_url % country_code - logger.info("Starting to download %s" % url) + logger.info("Starting to download %s", url) res_request = requests.get(url, timeout=15) if res_request.status_code != requests.codes.ok: # pylint: disable=translation-positional-used - Don't want to re-translate raise UserError( - _("Got an error %d when trying to download the file %s.") - % (res_request.status_code, url) + self.env._( + "Got an error %d when trying to download the file %s.", + res_request.status_code, + url, + ) ) f_geonames = zipfile.ZipFile(io.BytesIO(res_request.content)) tempdir = tempfile.mkdtemp(prefix="odoo") - f_geonames.extract("%s.txt" % country_code, tempdir) + f_geonames.extract(f"{country_code}.txt", tempdir) - data_file = open( - os.path.join(tempdir, "%s.txt" % country_code), encoding="utf-8" - ) + data_file = open(os.path.join(tempdir, f"{country_code}.txt"), encoding="utf-8") data_file.seek(0) reader = csv.reader(data_file, delimiter=" ") parsed_csv = [row for i, row in enumerate(reader)] @@ -202,17 +203,17 @@ def _action_remove_old_records(self, model_name, old_records, country): model = self.env[model_name] items = model.browse(list(old_records)) try: - logger.info("removing %s entries" % model._name) + logger.info("removing %s entries", model._name) items.unlink() logger.info( - "%d entries deleted for country %s" % (len(old_records), country.name) + "%d entries deleted for country %s", len(old_records), country.name ) except Exception: for item in items: try: item.unlink() except Exception: - logger.info(_("%d could not be deleted %") % item.name) + logger.info(self.env._("%s could not be deleted", item.name)) def _process_csv(self, parsed_csv, country): state_model = self.env["res.country.state"] diff --git a/base_location_geonames_import/wizard/geonames_import_view.xml b/base_location_geonames_import/wizard/geonames_import_view.xml index 9a1c8f33605..ab323e9ddef 100644 --- a/base_location_geonames_import/wizard/geonames_import_view.xml +++ b/base_location_geonames_import/wizard/geonames_import_view.xml @@ -7,9 +7,9 @@

    For the selected country, this wizard will download the latest version of the list of cities from geonames.org, create new location entries if not found already in the system, and delete missing entries from new file.

    + href="http://www.geonames.org/" + >geonames.org, create new location entries if not found already in the system, and delete missing entries from new file.