Skip to content

Commit

Permalink
[15.0][MIG] l10n_nl_oin
Browse files Browse the repository at this point in the history
  • Loading branch information
astirpe committed Jan 24, 2023
1 parent 733dd68 commit ef9f29f
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 64 deletions.
9 changes: 5 additions & 4 deletions l10n_nl_oin/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ Organisatie-identificatienummer (OIN)
:target: https://runbot.odoo-community.org/runbot/176/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds the Dutch `Organisatie-identificatienummer (OIN)` field
This module validates the Dutch `Organisatie-identificatienummer (OIN)` field
on partner forms.

The field is visible when the field ``company_type`` is set to ``Company``.
The field is visible when the field ``company_type`` is set to ``Company``
and when the Country is ``The Netherlands``.

A double check on the OIN is done when inserting/modifying its value:

Expand Down Expand Up @@ -92,7 +93,7 @@ promote its widespread use.

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-astirpe|
|maintainer-astirpe|

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

Expand Down
4 changes: 2 additions & 2 deletions l10n_nl_oin/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

{
"name": "Organisatie-identificatienummer (OIN)",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"category": "Dutch Localization",
"license": "AGPL-3",
"summary": "Adds Dutch OIN field",
"author": "Onestein, Odoo Community Association (OCA)",
"maintainers": ["astirpe"],
"website": "https://github.com/OCA/l10n-netherlands",
"data": ["views/res_partner.xml"],
"depends": ["l10n_nl"],
"installable": True,
}
23 changes: 23 additions & 0 deletions l10n_nl_oin/migrations/15.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
"""In the Dutch localization of Odoo 15.0 a new field 'l10n_nl_oin' was added.
This method renames old field 'nl_oin' to 'l10n_nl_oin', in order to preserve
existing values.
"""
openupgrade.rename_fields(
env,
[
(
"res.partner",
"res_partner",
"nl_oin",
"l10n_nl_oin",
)
],
)
36 changes: 14 additions & 22 deletions l10n_nl_oin/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,19 @@
class ResPartner(models.Model):
_inherit = "res.partner"

nl_oin = fields.Char(
"Dutch OIN", copy=False, help="Dutch Organisatie-identificatienummer (OIN)"
l10n_nl_oin = fields.Char(
copy=False, help="Dutch Organisatie-identificatienummer (OIN)"
)
nl_oin_display = fields.Boolean(compute="_compute_nl_oin_display")

@api.depends("country_id", "company_type")
def _compute_nl_oin_display(self):
for partner in self:
if partner.company_type != "company":
partner.nl_oin_display = False
elif partner.country_id != self.env.ref("base.nl"):
partner.nl_oin_display = False
else:
partner.nl_oin_display = True

@api.onchange("nl_oin")

@api.onchange("l10n_nl_oin")
def onchange_nl_oin(self):
warning = {}
if self.nl_oin:
if self.l10n_nl_oin:
# check is valid, otherwise display a warning
warning = self._warn_oin_invalid()

# search for another partner with the same OIN
args = [("nl_oin", "=", self.nl_oin), ("name", "!=", self.name)]
args = [("l10n_nl_oin", "=", self.l10n_nl_oin), ("name", "!=", self.name)]

# refine search in case of multicompany setting
if self.company_id:
Expand All @@ -45,16 +34,19 @@ def onchange_nl_oin(self):
def _warn_oin_invalid(self):
self.ensure_one()
warning = {}
if len(self.nl_oin) != 20 or not self.nl_oin.isdigit():
msg = _("The OIN you entered (%s) is not valid.")
warning = {"title": _("Warning!"), "message": msg % self.nl_oin}
if len(self.l10n_nl_oin) != 20 or not self.l10n_nl_oin.isdigit():
msg = _("The OIN you entered (%(oin)s) is not valid.")
warning = {
"title": _("Warning!"),
"message": msg % {"oin": self.l10n_nl_oin},
}
return warning

def _warn_oin_existing(self):
self.ensure_one()
msg = _("Another partner (%s) has the same OIN (%s).")
msg = _("Another partner (%(name)s) has the same OIN (%(oin)s).")
warning = {
"title": _("Warning!"),
"message": msg % (self.name, self.nl_oin),
"message": msg % {"name": self.name, "oin": self.l10n_nl_oin},
}
return warning
5 changes: 3 additions & 2 deletions l10n_nl_oin/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
This module adds the Dutch `Organisatie-identificatienummer (OIN)` field
This module validates the Dutch `Organisatie-identificatienummer (OIN)` field
on partner forms.

The field is visible when the field ``company_type`` is set to ``Company``.
The field is visible when the field ``company_type`` is set to ``Company``
and when the Country is ``The Netherlands``.

A double check on the OIN is done when inserting/modifying its value:

Expand Down
22 changes: 6 additions & 16 deletions l10n_nl_oin/tests/test_l10n_nl_oin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def setUp(self):
)

def test_01_oin_not_valid(self):
self.partner_oin.nl_oin = "123"
self.partner_oin.l10n_nl_oin = "123"
res = self.partner_oin.onchange_nl_oin()
self.assertEqual(self.partner_oin.nl_oin, "123")
self.assertEqual(self.partner_oin.l10n_nl_oin, "123")
warning = res.get("warning")
self.assertTrue(warning)
message = warning.get("message")
Expand All @@ -32,21 +32,21 @@ def test_01_oin_not_valid(self):
self.assertEqual(title, "Warning!")

def test_02_oin_valid(self):
self.partner_oin.nl_oin = "12345678901234567890"
self.partner_oin.l10n_nl_oin = "12345678901234567890"
res = self.partner_oin.onchange_nl_oin()
self.assertEqual(self.partner_oin.nl_oin, "12345678901234567890")
self.assertEqual(self.partner_oin.l10n_nl_oin, "12345678901234567890")
warning = res.get("warning")
self.assertFalse(warning)

def test_03_oin_another_partner(self):
new_partner_oin = self.env["res.partner"].create(
{
"name": "Partner with OIN - NEW",
"nl_oin": "12345678901234567890",
"l10n_nl_oin": "12345678901234567890",
"company_id": self.env.company.id,
}
)
self.partner_oin.nl_oin = "12345678901234567890"
self.partner_oin.l10n_nl_oin = "12345678901234567890"
res = self.partner_oin.onchange_nl_oin()
self.assertTrue(res.get("warning"))
warning = new_partner_oin._warn_oin_existing()
Expand All @@ -62,13 +62,3 @@ def test_03_oin_another_partner(self):
self.assertTrue(title)
self.assertEqual(title, "Warning!")
self.assertEqual(title, res["warning"]["title"])

def test_03_oin_display(self):
self.assertTrue(self.partner_oin.nl_oin_display)

self.partner_oin.country_id = self.env.ref("base.be")
self.assertFalse(self.partner_oin.nl_oin_display)

self.partner_oin.country_id = self.env.ref("base.nl")
self.partner_oin.company_type = "person"
self.assertFalse(self.partner_oin.nl_oin_display)
18 changes: 0 additions & 18 deletions l10n_nl_oin/views/res_partner.xml

This file was deleted.

1 change: 1 addition & 0 deletions setup/l10n_nl_oin/odoo/addons/l10n_nl_oin
6 changes: 6 additions & 0 deletions setup/l10n_nl_oin/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit ef9f29f

Please sign in to comment.