From e07c1d6faa7944d8e716fd338cefde054856f3a5 Mon Sep 17 00:00:00 2001 From: Franco Tampieri Date: Wed, 3 Jan 2018 21:23:46 +0100 Subject: [PATCH] [IMP] base_location_geonames_import: Add conf for selecting state columns based on country_id (#534) --- base_location_geonames_import/README.rst | 1 + base_location_geonames_import/__init__.py | 1 + base_location_geonames_import/__manifest__.py | 4 +++- .../data/res_country_data.xml | 11 +++++++++++ .../models/__init__.py | 5 +++++ .../models/res_country.py | 17 +++++++++++++++++ .../views/res_country_view.xml | 15 +++++++++++++++ .../wizard/geonames_import.py | 4 ++++ 8 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 base_location_geonames_import/data/res_country_data.xml create mode 100644 base_location_geonames_import/models/__init__.py create mode 100644 base_location_geonames_import/models/res_country.py create mode 100644 base_location_geonames_import/views/res_country_view.xml diff --git a/base_location_geonames_import/README.rst b/base_location_geonames_import/README.rst index c37fdadeb..62eac8eab 100644 --- a/base_location_geonames_import/README.rst +++ b/base_location_geonames_import/README.rst @@ -63,6 +63,7 @@ Contributors * Pedro M. Baeza * Dave Lasley * Jordi Ballester +* Franco Tampieri Icon ---- diff --git a/base_location_geonames_import/__init__.py b/base_location_geonames_import/__init__.py index 3b4c3edf0..35e7c9600 100644 --- a/base_location_geonames_import/__init__.py +++ b/base_location_geonames_import/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- +from . import models from . import wizard diff --git a/base_location_geonames_import/__manifest__.py b/base_location_geonames_import/__manifest__.py index 4462f7a99..f1e2da919 100644 --- a/base_location_geonames_import/__manifest__.py +++ b/base_location_geonames_import/__manifest__.py @@ -9,7 +9,7 @@ { 'name': 'Base Location Geonames Import', - 'version': '11.0.1.0.1', + 'version': '11.0.1.1.1', 'category': 'Partner Management', 'license': 'AGPL-3', 'summary': 'Import better zip entries from Geonames', @@ -22,6 +22,8 @@ 'depends': ['base_location'], 'external_dependencies': {'python': ['requests']}, 'data': [ + 'data/res_country_data.xml', + 'views/res_country_view.xml', 'wizard/geonames_import_view.xml', ], 'installable': True, diff --git a/base_location_geonames_import/data/res_country_data.xml b/base_location_geonames_import/data/res_country_data.xml new file mode 100644 index 000000000..78a41cb08 --- /dev/null +++ b/base_location_geonames_import/data/res_country_data.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/base_location_geonames_import/models/__init__.py b/base_location_geonames_import/models/__init__.py new file mode 100644 index 000000000..3a4c215d4 --- /dev/null +++ b/base_location_geonames_import/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Franco Tampieri, Freelancer http://franco.tampieri.info +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import res_country diff --git a/base_location_geonames_import/models/res_country.py b/base_location_geonames_import/models/res_country.py new file mode 100644 index 000000000..279d2ce79 --- /dev/null +++ b/base_location_geonames_import/models/res_country.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Franco Tampieri, Freelancer http://franco.tampieri.info +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCountryState(models.Model): + + _inherit = 'res.country' + + geonames_state_name_column = fields.Integer( + 'Geonames State Name Column', + ) + geonames_state_code_column = fields.Integer( + 'Geonames State Code Column', + ) diff --git a/base_location_geonames_import/views/res_country_view.xml b/base_location_geonames_import/views/res_country_view.xml new file mode 100644 index 000000000..d2bfb63dc --- /dev/null +++ b/base_location_geonames_import/views/res_country_view.xml @@ -0,0 +1,15 @@ + + + + res.country.geonames.form + res.country + + form + + + + + + + + diff --git a/base_location_geonames_import/wizard/geonames_import.py b/base_location_geonames_import/wizard/geonames_import.py index f3f24a5c7..163491f27 100644 --- a/base_location_geonames_import/wizard/geonames_import.py +++ b/base_location_geonames_import/wizard/geonames_import.py @@ -164,6 +164,10 @@ class BetterZipGeonamesImport(models.TransientModel): @api.model def select_or_create_state( self, row, country, code_row_index=4, name_row_index=3): + if country.geonames_state_code_column: + code_row_index = country.geonames_state_code_column + if country.geonames_state_name_column: + name_row_index = country.geonames_state_name_column return self._get_state( country.id, row[code_row_index], row[name_row_index], )