Skip to content

Commit

Permalink
[IMP] l10n_de_toponyms: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
hkapatel-initos committed Sep 2, 2021
1 parent 1a0cbbb commit bb5eb52
Show file tree
Hide file tree
Showing 9 changed files with 33,040 additions and 33,016 deletions.
6 changes: 2 additions & 4 deletions l10n_de_toponyms/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
{
"name": "German Toponyms",
"version": "11.0.1.0.0",
"author": "IT IS AG Germany, "
"initOS GmbH, "
"Odoo Community Association (OCA)",
"author": "IT IS AG Germany, " "initOS GmbH, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-germany",
"category": "Localization",
"depends": [
Expand All @@ -18,5 +16,5 @@
"wizard/l10n_de_toponyms_wizard.xml",
"wizard/l10n_de_toponyms_zipcodes.xml",
],
'installable': True,
"installable": True,
}
14 changes: 8 additions & 6 deletions l10n_de_toponyms/tests/test_l10n_de_toponyms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class TestL10nDeToponyms(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestL10nDeToponyms, cls).setUpClass()
cls.wizard = cls.env['config.de.toponyms'].create({
'name': '',
})
cls.wizard = cls.env["config.de.toponyms"].create(
{
"name": "",
}
)

def test_import(self):
self.wizard.with_context(max_import=10).execute()
zips = self.env['res.better.zip'].search([
('country_id', '=', self.env.ref('base.de').id)
])
zips = self.env["res.better.zip"].search(
[("country_id", "=", self.env.ref("base.de").id)]
)
self.assertTrue(zips)
51 changes: 28 additions & 23 deletions l10n_de_toponyms/tools/gen_toponyms_geonames.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,56 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import csv
import requests
import zipfile
from io import BytesIO

import requests

COUNTRY_CODE = "DE"


if __name__ == "__main__":
url = "http://download.geonames.org/export/zip/%s.zip" % COUNTRY_CODE

print('Downloading from %s' % url)
print("Downloading from %s" % url)
response = requests.get(url)
if response.status_code != requests.codes.ok:
print('Error while downloading: %s.' % response.status_code)
print("Error while downloading: %s." % response.status_code)
exit(response.status_code)

print('Decompressing archive...')
zipped = zipfile.ZipFile(BytesIO(response.content), 'r')
data = zipped.read('%s.txt' % COUNTRY_CODE).decode('UTF-8').splitlines()
print("Decompressing archive...")
zipped = zipfile.ZipFile(BytesIO(response.content), "r")
data = zipped.read("%s.txt" % COUNTRY_CODE).decode("UTF-8").splitlines()

dialect = csv.excel
dialect.delimiter = "\t"
reader = csv.reader(data, dialect=dialect)

print('Generate the XML...')
output = open("l10n_de_toponyms_zipcodes.xml", 'w')
print("Generate the XML...")
output = open("l10n_de_toponyms_zipcodes.xml", "w")
output.write('<?xml version="1.0" encoding="UTF-8"?>\n')
output.write('<odoo noupdate="1">\n')
for k, row in enumerate(reader):
zipcode, city, _, state_code = row[1: 5]
zipcode, city, _, state_code = row[1:5]
state = "l10n_de_country_states.res_country_state_%s" % state_code
city_id = "city_DE_%s" % k
lat, lon = row[9: 11]

output.write(''.join([
' ' * 8 + '<record id="%s" model="res.better.zip">\n' % city_id,
' ' * 12 + '<field name="state_id" ref="%s"/>\n' % state,
' ' * 12 + '<field name="city">%s</field>\n' % city,
' ' * 12 + '<field name="name">%s</field>\n' % zipcode,
' ' * 12 + '<field name="country_id" ref="base.de"/>\n',
' ' * 12 + '<field name="latitude">%s</field>\n' % lat,
' ' * 12 + '<field name="longitude">%s</field>\n' % lon,
' ' * 8 + '</record>\n',
]))

output.write('</odoo>\n')
lat, lon = row[9:11]

output.write(
"".join(
[
" " * 8 + '<record id="%s" model="res.better.zip">\n' % city_id,
" " * 12 + '<field name="state_id" ref="%s"/>\n' % state,
" " * 12 + '<field name="city">%s</field>\n' % city,
" " * 12 + '<field name="name">%s</field>\n' % zipcode,
" " * 12 + '<field name="country_id" ref="base.de"/>\n',
" " * 12 + '<field name="latitude">%s</field>\n' % lat,
" " * 12 + '<field name="longitude">%s</field>\n' % lon,
" " * 8 + "</record>\n",
]
)
)

output.write("</odoo>\n")
output.close()
print("Done.")
24 changes: 13 additions & 11 deletions l10n_de_toponyms/wizard/l10n_de_toponyms_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@
# Copyright 2018 IT IS AG <oca@itis.de>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models, fields, api, tools
import os

from odoo import api, fields, models, tools


class ConfigDeToponyms(models.TransientModel):
_name = 'config.de.toponyms'
_inherit = 'res.config.installer'
_name = "config.de.toponyms"
_inherit = "res.config.installer"

name = fields.Char('Name', size=64)
name = fields.Char("Name", size=64)

@api.model
def create_zipcodes(self):
"""Import spanish zipcodes information through an XML file."""
file_name = 'l10n_de_toponyms_zipcodes.xml'
path = os.path.join('l10n_de_toponyms', 'wizard', file_name)
file_name = "l10n_de_toponyms_zipcodes.xml"
path = os.path.join("l10n_de_toponyms", "wizard", file_name)
with tools.file_open(path) as fp:
tools.convert_xml_import(self.env.cr, 'l10n_de_toponyms', fp, {},
'init', noupdate=True)
tools.convert_xml_import(
self.env.cr, "l10n_de_toponyms", fp, {}, "init", noupdate=True
)
return True

@api.multi
def execute(self):
res = super(ConfigDeToponyms, self).execute()
wizard_obj = self.env['better.zip.geonames.import']
country_es = self.env['res.country'].search([('code', '=', 'DE')])
wizard = wizard_obj.create({'country_id': country_es.id})
wizard_obj = self.env["better.zip.geonames.import"]
country_es = self.env["res.country"].search([("code", "=", "DE")])
wizard = wizard_obj.create({"country_id": country_es.id})
wizard.run_import()
return res

Expand Down
26 changes: 17 additions & 9 deletions l10n_de_toponyms/wizard/l10n_de_toponyms_wizard.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_confirm_toponyms_de_form" model="ir.ui.view">
<field name="name">config.de.toponyms</field>
<field name="model">config.de.toponyms</field>
<field name="inherit_id" ref="base.res_config_installer"/>
<field name="inherit_id" ref="base.res_config_installer" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<form position="attributes">
<attribute name="string">German cities configuration</attribute>
</form>
<separator position="replace">
<group col="2" colspan="4" string="This wizard will add city and state information to zip codes">
<label colspan="2" string="Warning! Adding this bunch of records can take a lot of time. If you are behind a SSL proxy, check your timeout."/>
<group
col="2"
colspan="4"
string="This wizard will add city and state information to zip codes"
>
<label
colspan="2"
string="Warning! Adding this bunch of records can take a lot of time. If you are behind a SSL proxy, check your timeout."
/>
</group>
</separator>
<button name="action_next" position="after">
<button string="Configure from local"
type="object"
name="execute_local"
<button
string="Configure from local"
type="object"
name="execute_local"
/>
</button>
<button name="action_next" position="attributes">
Expand All @@ -29,7 +37,7 @@
<record id="action_config_toponyms_de_form" model="ir.actions.act_window">
<field name="name">German toponyms configuration</field>
<field name="res_model">config.de.toponyms</field>
<field name="view_id" ref="view_confirm_toponyms_de_form"/>
<field name="view_id" ref="view_confirm_toponyms_de_form" />
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
Expand All @@ -38,7 +46,7 @@
<!-- register on configuration -->
<record id="config_wizard_toponyms_de" model="ir.actions.todo">
<field name="name">German toponyms configuration</field>
<field name="action_id" ref="action_config_toponyms_de_form"/>
<field name="action_id" ref="action_config_toponyms_de_form" />
<field name="sequence">20</field>
</record>

Expand Down
Loading

0 comments on commit bb5eb52

Please sign in to comment.