Skip to content

Commit

Permalink
[13.0][MIG] l10n_nl_postcode
Browse files Browse the repository at this point in the history
  • Loading branch information
astirpe committed Oct 31, 2019
1 parent e29b726 commit c10bc31
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ line_length=88
known_odoo=odoo
known_odoo_addons=odoo.addons
sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER
known_third_party=
known_third_party=setuptools
10 changes: 5 additions & 5 deletions l10n_nl_postcode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Dutch postcode validation for Partners
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--netherlands-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-netherlands/tree/12.0/l10n_nl_postcode
:target: https://github.com/OCA/l10n-netherlands/tree/13.0/l10n_nl_postcode
:alt: OCA/l10n-netherlands
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-netherlands-12-0/l10n-netherlands-12-0-l10n_nl_postcode
:target: https://translation.odoo-community.org/projects/l10n-netherlands-13-0/l10n-netherlands-13-0-l10n_nl_postcode
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/176/12.0
:target: https://runbot.odoo-community.org/runbot/176/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -62,7 +62,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-netherlands/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/l10n-netherlands/issues/new?body=module:%20l10n_nl_postcode%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/l10n-netherlands/issues/new?body=module:%20l10n_nl_postcode%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -92,6 +92,6 @@ 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.

This module is part of the `OCA/l10n-netherlands <https://github.com/OCA/l10n-netherlands/tree/12.0/l10n_nl_postcode>`_ project on GitHub.
This module is part of the `OCA/l10n-netherlands <https://github.com/OCA/l10n-netherlands/tree/13.0/l10n_nl_postcode>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
22 changes: 9 additions & 13 deletions l10n_nl_postcode/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Copyright 2016-2018 Onestein (<http://www.onestein.eu>)
# Copyright 2016-2019 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Dutch postcode validation for Partners',
'version': '12.0.1.0.0',
'category': 'Localization',
'author': 'Onestein,Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/l10n-netherlands',
'license': 'AGPL-3',
'depends': [
'base',
],
'external_dependencies': {
'python': ['stdnum'],
},
"name": "Dutch postcode validation for Partners",
"version": "13.0.1.0.0",
"category": "Localization",
"author": "Onestein,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-netherlands",
"license": "AGPL-3",
"depends": ["base"],
"external_dependencies": {"python": ["python-stdnum"]},
}
27 changes: 10 additions & 17 deletions l10n_nl_postcode/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2018 Onestein (<http://www.onestein.eu>)
# Copyright 2016-2019 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging
Expand All @@ -9,35 +9,28 @@
try:
from stdnum.nl import postcode
except ImportError:
_logger.debug('Cannot import stdnum.nl.postcode.')
_logger.debug("Cannot import stdnum.nl.postcode.")


class ResPartner(models.Model):
_inherit = 'res.partner'
_inherit = "res.partner"

@api.multi
def _l10n_nl_postcode_get_warning(self):
self.ensure_one()
msg = _('The Postcode you entered (%s) is not valid.')
warning = {
'title': _('Warning!'),
'message': msg % self.zip,
}
return warning

@api.multi
msg = _("The Postcode you entered (%s) is not valid.")
return {"title": _("Warning!"), "message": msg % self.zip}

def _l10n_nl_postcode_check_country(self):
self.ensure_one()
country = self.country_id
if not country or country != self.env.ref('base.nl'):
if not country or country != self.env.ref("base.nl"):
return False
return True

@api.multi
@api.onchange('zip', 'country_id')
@api.onchange("zip", "country_id")
def onchange_zip_l10n_nl_postcode(self):
# if 'skip_postcode_check' passed in context: will disable the check
if self.env.context.get('skip_postcode_check'):
if self.env.context.get("skip_postcode_check"):
return

if self.zip and self._l10n_nl_postcode_check_country():
Expand All @@ -48,4 +41,4 @@ def onchange_zip_l10n_nl_postcode(self):
else:
# display a warning
warning_msg = self._l10n_nl_postcode_get_warning()
return {'warning': warning_msg, }
return {"warning": warning_msg}
54 changes: 17 additions & 37 deletions l10n_nl_postcode/tests/test_l10n_nl_postcode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017-2018 Onestein (<http://www.onestein.eu>)
# Copyright 2017-2019 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests import common
Expand All @@ -7,73 +7,53 @@

class TestL10NNLPostcode(common.TransactionCase):
def setUp(self):
super(TestL10NNLPostcode, self).setUp()
self.partner = self.env.ref('base.res_partner_3')
super().setUp()
self.partner = self.env.ref("base.res_partner_3")

def test_01_onchange_with_non_blocking_warning(self):
self.partner.write({
'country_id': self.env.ref('base.nl').id,
'zip': '80021',
})
self.partner.write({"country_id": self.env.ref("base.nl").id, "zip": "80021"})

warning = self.partner.onchange_zip_l10n_nl_postcode()
msg = _('The Postcode you entered (%s) is not valid.')
tst_warning = {'warning': {
'title': _('Warning!'),
'message': msg % '80021',
}}
msg = _("The Postcode you entered (%s) is not valid.")
tst_warning = {"warning": {"title": _("Warning!"), "message": msg % "80021"}}
self.assertTrue(warning)
self.assertEqual(warning, tst_warning)
# zip didn't change
self.assertEqual(self.partner.zip, '80021')
self.assertEqual(self.partner.zip, "80021")

def test_02_onchange_no_country(self):
self.partner.write({
'zip': '4813LE',
})
self.partner.write({"zip": "4813LE"})
res = self.partner.onchange_zip_l10n_nl_postcode()
self.assertFalse(res)
# zip didn't change
self.assertEqual(self.partner.zip, '4813LE')
self.assertEqual(self.partner.zip, "4813LE")

def test_03_onchange_other_country(self):
self.partner.write({
'country_id': self.env.ref('base.be').id,
'zip': '4813LE',
})
self.partner.write({"country_id": self.env.ref("base.be").id, "zip": "4813LE"})
res = self.partner.onchange_zip_l10n_nl_postcode()
self.assertFalse(res)
# zip didn't change
self.assertEqual(self.partner.zip, '4813LE')
self.assertEqual(self.partner.zip, "4813LE")

def test_04_onchange_format(self):
self.partner.write({
'country_id': self.env.ref('base.nl').id,
'zip': '4813LE',
})
self.partner.write({"country_id": self.env.ref("base.nl").id, "zip": "4813LE"})
res = self.partner.onchange_zip_l10n_nl_postcode()
self.assertFalse(res)
# zip formatted
self.assertEqual(self.partner.zip, '4813 LE')
self.assertEqual(self.partner.zip, "4813 LE")

def test_05_onchange_format(self):
self.partner.write({
'country_id': self.env.ref('base.nl').id,
'zip': '4813 le',
})
self.partner.write({"country_id": self.env.ref("base.nl").id, "zip": "4813 le"})
res = self.partner.onchange_zip_l10n_nl_postcode()
self.assertFalse(res)
# zip formatted
self.assertEqual(self.partner.zip, '4813 LE')
self.assertEqual(self.partner.zip, "4813 LE")

def test_06_skip_onchange(self):
self.partner.write({
'country_id': self.env.ref('base.nl').id,
'zip': '4813 le',
})
self.partner.write({"country_id": self.env.ref("base.nl").id, "zip": "4813 le"})
res = self.partner.with_context(
skip_postcode_check=True
).onchange_zip_l10n_nl_postcode()
self.assertFalse(res)
# zip didn't change
self.assertEqual(self.partner.zip, '4813 le')
self.assertEqual(self.partner.zip, "4813 le")

0 comments on commit c10bc31

Please sign in to comment.