diff --git a/l10n_nl_oin/README.rst b/l10n_nl_oin/README.rst index fd61ad355..7c94d0fd5 100644 --- a/l10n_nl_oin/README.rst +++ b/l10n_nl_oin/README.rst @@ -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: @@ -92,7 +93,7 @@ promote its widespread use. Current `maintainer `__: -|maintainer-astirpe| +|maintainer-astirpe| This module is part of the `OCA/l10n-netherlands `_ project on GitHub. diff --git a/l10n_nl_oin/__manifest__.py b/l10n_nl_oin/__manifest__.py index 4ebaaf510..ff4d92baa 100644 --- a/l10n_nl_oin/__manifest__.py +++ b/l10n_nl_oin/__manifest__.py @@ -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, } diff --git a/l10n_nl_oin/migrations/15.0.1.0.0/pre-migration.py b/l10n_nl_oin/migrations/15.0.1.0.0/pre-migration.py new file mode 100644 index 000000000..59157fa54 --- /dev/null +++ b/l10n_nl_oin/migrations/15.0.1.0.0/pre-migration.py @@ -0,0 +1,23 @@ +# Copyright 2023 Onestein () +# 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", + ) + ], + ) diff --git a/l10n_nl_oin/models/res_partner.py b/l10n_nl_oin/models/res_partner.py index e7204991e..c5f2e34e4 100644 --- a/l10n_nl_oin/models/res_partner.py +++ b/l10n_nl_oin/models/res_partner.py @@ -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: @@ -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 diff --git a/l10n_nl_oin/readme/DESCRIPTION.rst b/l10n_nl_oin/readme/DESCRIPTION.rst index 13b9e929a..109b472ab 100644 --- a/l10n_nl_oin/readme/DESCRIPTION.rst +++ b/l10n_nl_oin/readme/DESCRIPTION.rst @@ -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: diff --git a/l10n_nl_oin/tests/test_l10n_nl_oin.py b/l10n_nl_oin/tests/test_l10n_nl_oin.py index 44c159ec0..ee1aaab45 100644 --- a/l10n_nl_oin/tests/test_l10n_nl_oin.py +++ b/l10n_nl_oin/tests/test_l10n_nl_oin.py @@ -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") @@ -32,9 +32,9 @@ 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) @@ -42,11 +42,11 @@ 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() @@ -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) diff --git a/l10n_nl_oin/views/res_partner.xml b/l10n_nl_oin/views/res_partner.xml deleted file mode 100644 index 729b31d36..000000000 --- a/l10n_nl_oin/views/res_partner.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - res.partner - - - - - - - - - diff --git a/setup/l10n_nl_oin/odoo/addons/l10n_nl_oin b/setup/l10n_nl_oin/odoo/addons/l10n_nl_oin new file mode 120000 index 000000000..5bdc7d6a2 --- /dev/null +++ b/setup/l10n_nl_oin/odoo/addons/l10n_nl_oin @@ -0,0 +1 @@ +../../../../l10n_nl_oin \ No newline at end of file diff --git a/setup/l10n_nl_oin/setup.py b/setup/l10n_nl_oin/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/l10n_nl_oin/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)