Skip to content

Commit

Permalink
[MIG] base_location_geonames_import: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimkhoi3010 committed Oct 15, 2024
1 parent b738693 commit 393a4a9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
9 changes: 9 additions & 0 deletions base_location_geonames_import/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ Contributors
- Franco Tampieri <[email protected]>
- Aitor Bouzas <[email protected]>
- Manuel Regidor <[email protected]>
- Khoi (Kien Kim) <[email protected]>

Other credits
-------------

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

- Camptocamp.

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion base_location_geonames_import/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions base_location_geonames_import/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- Franco Tampieri \<<[email protected]>\>
- Aitor Bouzas \<<[email protected]>\>
- Manuel Regidor \<<[email protected]>\>
- Khoi (Kien Kim) \<<[email protected]>\>
3 changes: 3 additions & 0 deletions base_location_geonames_import/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The migration of this module from 17.0 to 18.0 was financially supported by:

- Camptocamp.
14 changes: 12 additions & 2 deletions base_location_geonames_import/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ <h1 class="title">Base Location Geonames Import</h1>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-7">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-8">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -433,10 +434,19 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Franco Tampieri &lt;<a class="reference external" href="mailto:franco&#64;tampieri.info">franco&#64;tampieri.info</a>&gt;</li>
<li>Aitor Bouzas &lt;<a class="reference external" href="mailto:aitor.bouzas&#64;adaptivecity.com">aitor.bouzas&#64;adaptivecity.com</a>&gt;</li>
<li>Manuel Regidor &lt;<a class="reference external" href="mailto:manuel.regidor&#64;sygel.es">manuel.regidor&#64;sygel.es</a>&gt;</li>
<li>Khoi (Kien Kim) &lt;<a class="reference external" href="mailto:khoikk&#64;trobz.com">khoikk&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-7">Other credits</a></h2>
<p>The migration of this module from 17.0 to 18.0 was financially supported
by:</p>
<ul class="simple">
<li>Camptocamp.</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand Down
23 changes: 12 additions & 11 deletions base_location_geonames_import/wizard/geonames_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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._("%d could not be deleted %", item.name))

def _process_csv(self, parsed_csv, country):
state_model = self.env["res.country.state"]
Expand Down

0 comments on commit 393a4a9

Please sign in to comment.