-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] l10n_nl_postcodeapi: improved code and compatibility
- Loading branch information
1 parent
0ad0b99
commit 8463141
Showing
16 changed files
with
329 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,9 @@ Installation | |
This module depends on the standard Odoo module base_address_extended, which will split | ||
up the street field into separate fields for street name and number. | ||
|
||
It now also depends on l10n_nl_country_states, to provide the names of the provinces, | ||
that will be added to the res_country_state model. | ||
|
||
You also need to have the 'pyPostcode' Python library by Stefan Jansen | ||
installed (https://pypi.python.org/pypi/pyPostcode). | ||
|
||
|
@@ -55,8 +58,22 @@ Please enter the API key that you request from PostcodeAPI into the system | |
parameter 'l10n_nl_postcodeapi.apikey' | ||
|
||
Provinces are auto-completed if a country state with the exact name is found in | ||
the system. A CSV file with the Dutch provinces is included in the data | ||
directory, but not loaded by default. You can import the file manually. | ||
the system. | ||
|
||
Changelog | ||
========= | ||
|
||
11.0.2.0.0 (2021-08-21) | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
- Now depend on l10n_nl_country_states to prevent conflicts with that module; | ||
- No manual caching of province data. It complicates code and performance gain | ||
will almost certainly be negligible; | ||
- Check valid Api Key in configuration immediately when setting or updating key; | ||
- Take into account that with l10n_nl_country_states installed, state_id on partner | ||
will in many cases be set, even if postcode api not active, or cannot find | ||
address; | ||
- Adjust tests to run properly on databases already containing data. | ||
|
||
Bug Tracker | ||
=========== | ||
|
@@ -81,6 +98,7 @@ Contributors | |
|
||
* Stefan Rijnhart (Therp BV) <[email protected]> | ||
* Andrea Stirpe <[email protected]> | ||
* Ronald Portier <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
@@ -95,6 +113,14 @@ 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. | ||
|
||
.. |maintainer-NL66278| image:: https://github.com/NL66278.png?size=40px | ||
:target: https://github.com/NL66278 | ||
:alt: NL66278 | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-NL66278| | ||
|
||
This module is part of the `OCA/l10n-netherlands <https://github.com/OCA/l10n-netherlands/tree/11.0/l10n_nl_postcodeapi>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
# Copyright 2013-2015 Therp BV <https://therp.nl> | ||
# Copyright 2013-2021 Therp BV <https://therp.nl> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Integration with PostcodeApi.nu', | ||
'summary': 'Autocomplete Dutch addresses using PostcodeApi.nu', | ||
'version': '11.0.1.0.0', | ||
'version': '11.0.2.0.0', | ||
'author': 'Therp BV,Odoo Community Association (OCA)', | ||
'category': 'Localization', | ||
'website': 'https://github.com/OCA/l10n-netherlands', | ||
'maintainers': ['NL66278'], # [email protected] | ||
'license': 'AGPL-3', | ||
'depends': ['base_address_extended'], | ||
'depends': [ | ||
'base_address_extended', | ||
'l10n_nl_country_states', | ||
], | ||
'data': [ | ||
'data/ir_config_parameter.xml', | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo noupdate="1"> | ||
|
||
<record id="parameter_apikey" model="ir.config_parameter"> | ||
<field name="key">l10n_nl_postcodeapi.apikey</field> | ||
<field name="value">Your API key</field> | ||
</record> | ||
|
||
</odoo> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
"""Import models for module.""" | ||
from . import res_partner | ||
from . import ir_config_parameter | ||
from . import res_country_state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,59 @@ | ||
# Copyright 2013-2015 Therp BV <https://therp.nl> | ||
# Copyright 2013-2021 Therp BV <https://therp.nl> | ||
# @autors: Stefan Rijnhart, Ronald Portier | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
"""Interface to the configured (or not) Postcode API.""" | ||
# pylint: disable=protected-access | ||
try: | ||
import pyPostcode | ||
except ImportError: | ||
pyPostcode = None | ||
|
||
from odoo import api, models | ||
from odoo.exceptions import UserError | ||
from odoo import api, models, _ | ||
from odoo.tools import ormcache | ||
|
||
|
||
class IrConfigParameter(models.Model): | ||
"""Interface to the configured (or not) Postcode API.""" | ||
_inherit = 'ir.config_parameter' | ||
|
||
@api.model | ||
@ormcache(skiparg=2) | ||
def get_provider_obj(self): | ||
"""get Api to interface with Dutch postcode provider.""" | ||
if not pyPostcode: | ||
# Module not loaded. | ||
return None # pragma: no cover | ||
apikey = self.sudo().get_param('l10n_nl_postcodeapi.apikey', '').strip() | ||
if not apikey or apikey == 'Your API key': | ||
return None | ||
provider_obj = pyPostcode.Api(apikey, (2, 0, 0)) | ||
test = provider_obj.getaddress('1053NJ', '334T') | ||
if not test or not test._data: | ||
raise UserError(_( | ||
'Could not verify the connection with the address lookup service' | ||
' (if you want to get rid of this message, please rename or delete' | ||
' the system parameter \'l10n_nl_postcodeapi.apikey\').' | ||
)) | ||
return provider_obj | ||
|
||
@api.model | ||
def create(self, vals): | ||
""" | ||
Clear the postcode provider cache when the API | ||
key is created | ||
""" | ||
if vals.get('key') == 'l10n_nl_postcodeapi.apikey': | ||
partner_obj = self.env['res.partner'] | ||
partner_obj.get_provider_obj.clear_cache(partner_obj) | ||
return super(IrConfigParameter, self).create(vals) | ||
"""Clear the postcode provider cache when the API key is created.""" | ||
new_record = super().create(vals) | ||
new_record._check_and_reset_provider() | ||
return new_record | ||
|
||
@api.multi | ||
def write(self, vals): | ||
""" | ||
Clear the postcode provider cache when the API | ||
key is modified | ||
""" | ||
key = 'l10n_nl_postcodeapi.apikey' | ||
if (vals.get('key') == key or | ||
self.search([('id', 'in', self.ids), ('key', '=', key)])): | ||
partner_obj = self.env['res.partner'] | ||
partner_obj.get_provider_obj.clear_cache(partner_obj) | ||
return super(IrConfigParameter, self).write(vals) | ||
"""Clear the postcode provider cache when the API key is modified.""" | ||
result = super().write(vals) | ||
self._check_and_reset_provider() | ||
return result | ||
|
||
def _check_and_reset_provider(self): | ||
"""Clear provider cache and check wether key valid.""" | ||
for this in self: | ||
if this.key == 'l10n_nl_postcodeapi.apikey': | ||
this.get_provider_obj.clear_cache(this) | ||
this.get_provider_obj() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.