Browse Source

Port base_location_geonames_import to v10

Add option to put city name all upper case
pull/643/head
Alexis de Lattre 8 years ago
committed by Pedro M. Baeza
parent
commit
8181787304
  1. 27
      base_location_geonames_import/README.rst
  2. 1
      base_location_geonames_import/__init__.py
  3. 6
      base_location_geonames_import/__manifest__.py
  4. 2
      base_location_geonames_import/tests/test_base_location_geonames_import.py
  5. 1
      base_location_geonames_import/wizard/__init__.py
  6. 23
      base_location_geonames_import/wizard/geonames_import.py
  7. 22
      base_location_geonames_import/wizard/geonames_import_view.xml

27
base_location_geonames_import/README.rst

@ -6,21 +6,21 @@
Base Location Geonames Import
=============================
This module adds a wizard to import better zip entries from Geonames database.
This module adds a wizard to import better zip entries from `Geonames <http://www.geonames.org/>`_ database.
Installation
============
For installing this module, you need these Python libraries: requests and
To install this module, you need these Python libraries: requests and
unicodecsv.
Configuration
=============
For seeing the menu, you need to activate *Technical features* option in your
user and to be *Sales manager*.
To access the menu to import better zip entries from Geonames, you must add yourself to the groups *Technical features* and *Sales manager*.
If want want/need to modify the default URL
(http://download.geonames.org/export/zip/), you can set the 'geonames.url'
(http://download.geonames.org/export/zip/), you can set the *geonames.url*
system parameter.
Usage
@ -36,8 +36,7 @@ better zip entries.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/9.0
:target: https://runbot.odoo-community.org/runbot/134/10.0
Bug Tracker
===========
@ -45,11 +44,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed `feedback
<https://github.com/OCA/
partner-contact/issues/new?body=module:%20
base_location_geonames_import%0Aversion:%20
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
@ -63,16 +58,16 @@ Contributors
Icon
----
* http://icon-park.com/icon/location-map-pin-orange3/
* http://commons.wikimedia.org/wiki/File:View-refresh.svg
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
:target: https://odoo-community.org
This module is maintained by the OCA.
@ -80,4 +75,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.

1
base_location_geonames_import/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import wizard

6
base_location_geonames_import/__manifest__.py

@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
# © 2014 Alexis de Lattre <alexis.delattre@akretion.com>
# © 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# © 2014 Lorenzo Battistini <lorenzo.battistini@agilebg.com>
# © 2016 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Base Location Geonames Import',
'version': '9.0.1.0.1',
'version': '10.0.1.0.0',
'category': 'Partner Management',
'license': 'AGPL-3',
'summary': 'Import better zip entries from Geonames',
@ -21,5 +21,5 @@
'data': [
'wizard/geonames_import_view.xml',
],
'installable': False,
'installable': True,
}

2
base_location_geonames_import/tests/test_base_location_geonames_import.py

@ -2,7 +2,7 @@
# © 2016 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests import common
from odoo.tests import common
class TestBaseLocationGeonamesImport(common.TransactionCase):

1
base_location_geonames_import/wizard/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import geonames_import

23
base_location_geonames_import/wizard/geonames_import.py

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# © 2014 Alexis de Lattre <alexis.delattre@akretion.com>
# © 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# © 2014 Lorenzo Battistini <lorenzo.battistini@agilebg.com>
# © 2016 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields, api, _
from openerp.exceptions import UserError
from odoo import models, fields, api, _
from odoo.exceptions import UserError
import requests
import tempfile
import StringIO
@ -27,10 +27,14 @@ class BetterZipGeonamesImport(models.TransientModel):
_rec_name = 'country_id'
country_id = fields.Many2one('res.country', 'Country', required=True)
title_case = fields.Boolean(
string='Title Case',
help='Converts retreived city and state names to Title Case.',
)
letter_case = fields.Selection([
('unchanged', 'Unchanged'),
('title', 'Title Case'),
('upper', 'Upper Case'),
], string='Letter Case', default='unchanged',
help="Converts retreived city and state names to Title Case "
"(upper case on each first letter of a word) or Upper Case "
"(all letters upper case).")
@api.model
def transform_city_name(self, city, country):
@ -66,9 +70,12 @@ class BetterZipGeonamesImport(models.TransientModel):
"correspond to the selected country (%s).")
% (row[0], country.code))
logger.debug('ZIP = %s - City = %s' % (row[1], row[2]))
if (self.title_case):
if self.letter_case.title:
row[2] = row[2].title()
row[3] = row[3].title()
elif self.letter_case.upper:
row[2] = row[2].upper()
row[3] = row[3].upper()
if row[1] and row[2]:
zip_model = self.env['res.better.zip']
zips = zip_model.search(self._domain_search_better_zip(

22
base_location_geonames_import/wizard/geonames_import_view.xml

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<record id="better_zip_geonames_import_form" model="ir.ui.view">
<field name="name">asterisk.server.company</field>
<field name="name">Import from Geonames form view</field>
<field name="model">better.zip.geonames.import</field>
<field name="arch" type="xml">
<form string="Import from Geonames">
<group name="help">
<div>
<p>For the selected country, this wizard will download the latest version of the list of cities from <a href="http://www.geonames.org/">geonames.org</a>, create new location entries if not found already in the system, and <b>delete missing entries</b> from new file.</p>
</div>
</group>
<group name="main">
<field name="country_id"/>
<label string="For the country selected above, 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."
colspan="2" name="import-help"/>
</group>
<group name="options">
<field name="title_case"/>
<field name="letter_case"/>
</group>
<footer>
<button name="run_import" type="object"
@ -27,15 +27,13 @@
<record id="better_zip_geonames_import_action" model="ir.actions.act_window">
<field name="name">Import from Geonames</field>
<field name="res_model">better.zip.geonames.import</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem id="better_zip_geonames_import_menu"
action="better_zip_geonames_import_action"
parent="base.menu_localisation"
parent="sales_team.menu_localisation"
sequence="50"/>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save