Skip to content

Commit

Permalink
Merge remote-tracking branch 'nl66278/11.0-fix-ln10n_nl_postcodeapi' …
Browse files Browse the repository at this point in the history
…into 11.0-use-github-actions
  • Loading branch information
NL66278 committed May 3, 2023
2 parents 9c7c088 + fb060bd commit 1050ec6
Show file tree
Hide file tree
Showing 16 changed files with 329 additions and 393 deletions.
30 changes: 28 additions & 2 deletions l10n_nl_postcodeapi/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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
===========
Expand All @@ -81,6 +98,7 @@ Contributors

* Stefan Rijnhart (Therp BV) <[email protected]>
* Andrea Stirpe <[email protected]>
* Ronald Portier <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -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.
11 changes: 7 additions & 4 deletions l10n_nl_postcodeapi/__manifest__.py
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',
],
Expand Down
2 changes: 0 additions & 2 deletions l10n_nl_postcodeapi/data/ir_config_parameter.xml
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>
13 changes: 0 additions & 13 deletions l10n_nl_postcodeapi/examples/res.country.state.csv

This file was deleted.

3 changes: 0 additions & 3 deletions l10n_nl_postcodeapi/i18n/nl.po
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,3 @@ msgstr ""
#: model:ir.model,name:l10n_nl_postcodeapi.model_ir_config_parameter
msgid "ir.config_parameter"
msgstr "ir.config_parameter"

#~ msgid "Partner"
#~ msgstr "Relatie"
50 changes: 0 additions & 50 deletions l10n_nl_postcodeapi/i18n/nl_NL.po

This file was deleted.

3 changes: 1 addition & 2 deletions l10n_nl_postcodeapi/models/__init__.py
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
66 changes: 46 additions & 20 deletions l10n_nl_postcodeapi/models/ir_config_parameter.py
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

Check warning on line 9 in l10n_nl_postcodeapi/models/ir_config_parameter.py

View check run for this annotation

Codecov / codecov/patch

l10n_nl_postcodeapi/models/ir_config_parameter.py#L8-L9

Added lines #L8 - L9 were not covered by tests

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()
39 changes: 0 additions & 39 deletions l10n_nl_postcodeapi/models/res_country_state.py

This file was deleted.

Loading

0 comments on commit 1050ec6

Please sign in to comment.