Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] [MIG] l10n_be_partner_identification #183

Merged
merged 15 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions l10n_be_partner_identification/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

======================================
Belgium Partner Identification Numbers
======================================

This addons extends *Partner Identification Numbers* to provide a number category for the 'Belgium national registration number' and for the Belgium ID Card number.
The category validate the number according the rules specific to the `Belgium national registration number <https://fr.wikipedia.org/wiki/Num%C3%A9ro_de_registre_national>`_.

Installation
============

No specific installation step required

Usage
=====
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/119/10.0


Known issues / Roadmap
======================

N/A

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/l10n-belgium/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-belgium/issues/new?body=module:%20
l10n_be_partner_identification%0Aversion:%20
10.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.


Credits
=======

Contributors
------------

* Laurent Mignon <[email protected]>
* Denis Roussel <[email protected]>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.

2 changes: 2 additions & 0 deletions l10n_be_partner_identification/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
13 changes: 13 additions & 0 deletions l10n_be_partner_identification/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Belgium Partner Identification Numbers",
"category": "Customer Relationship Management",
"version": "16.0.1.0.0",
"depends": ["partner_identification"],
"data": ["data/l10n_be_partner_identification.xml"],
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-belgium",
"license": "AGPL-3",
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record
model="res.partner.id_category"
id="l10n_be_national_registry_number_category"
>
<field name="name">Belgium national registration number</field>
<field name="code">be_nat_reg_num</field>
<field
name="validation_code"
><![CDATA[
failed = self.validate_l10n_be_national_registry_number(id_number)
]]></field>
</record>
<record model="res.partner.id_category" id="l10n_be_id_card_category">
<field name="name">Belgium ID Card</field>
<field name="code">be_id_card</field>
<field
name="validation_code"
><![CDATA[
failed = self.validate_l10n_be_id_card(id_number)
]]></field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_be_partner_identification
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: l10n_be_partner_identification
#: model:res.partner.id_category,name:l10n_be_partner_identification.l10n_be_id_card_category
msgid "Belgium ID Card"
msgstr ""

#. module: l10n_be_partner_identification
#: model:res.partner.id_category,name:l10n_be_partner_identification.l10n_be_national_registry_number_category
msgid "Belgium national registration number"
msgstr ""

#. module: l10n_be_partner_identification
#: model:ir.model,name:l10n_be_partner_identification.model_res_partner_id_category
msgid "Partner ID Category"
msgstr ""
2 changes: 2 additions & 0 deletions l10n_be_partner_identification/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import res_partner_id_category
64 changes: 64 additions & 0 deletions l10n_be_partner_identification/models/res_partner_id_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import datetime
import re

from odoo import api, models


class ResPartnerIdCategory(models.Model):
_inherit = "res.partner.id_category"

@api.model
def validate_l10n_be_national_registry_number(self, id_number):
"""Method called from the validation_code to validate a belgium
`Wikipedia
<https://fr.wikipedia.org/wiki/Num%C3%A9ro_de_registre_national>`_
The method doesn't support number for persons more than 100 years old.
"""
# replace all non digit char since on an identity card, the number is
# formatted as 85.01.01-002.00
num = re.sub("[^0-9]", "", id_number.name)
failed = True
if len(num) != 11:
return failed

Check warning on line 25 in l10n_be_partner_identification/models/res_partner_id_category.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_partner_identification/models/res_partner_id_category.py#L25

Added line #L25 was not covered by tests
if not num.isdigit():
return failed

Check warning on line 27 in l10n_be_partner_identification/models/res_partner_id_category.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_partner_identification/models/res_partner_id_category.py#L27

Added line #L27 was not covered by tests
seq = int(num[0:9])
YY = int(num[:2])
pivot_YY = datetime.date.today().year - 2000
if YY <= pivot_YY:
# the person is born after 31/12/1999
seq = seq + 2000000000
check = int(num[9:])
to_check = 97 - (seq % 97)
if check == 97 and to_check == 0:
return not failed

Check warning on line 37 in l10n_be_partner_identification/models/res_partner_id_category.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_partner_identification/models/res_partner_id_category.py#L37

Added line #L37 was not covered by tests
if to_check != check:
return failed
return not failed

@api.model
def validate_l10n_be_id_card(self, id_number):
"""Method called from the validation_code to validate a belgium id
card number
"""
# replace all non digit char since on an identity card, the number is
# formatted as 000-00000000-97
num = re.sub("[^0-9]", "", id_number.name)
failed = True
if len(num) != 12:
return failed

Check warning on line 52 in l10n_be_partner_identification/models/res_partner_id_category.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_partner_identification/models/res_partner_id_category.py#L52

Added line #L52 was not covered by tests
if not num.isdigit():
return failed

Check warning on line 54 in l10n_be_partner_identification/models/res_partner_id_category.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_partner_identification/models/res_partner_id_category.py#L54

Added line #L54 was not covered by tests
prefix = int(num[0:10])
suffix = int(num[-2:])
to_check = 97 - (prefix % 97)

if (to_check == 97 and to_check == suffix) or (
int(suffix) + int(to_check) == 97
):
return not failed
else:
return failed
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions l10n_be_partner_identification/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_l10n_be_partner_identification
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import odoo.tests.common as common
from odoo.exceptions import ValidationError


class TestL10nBePartnerIdentification(common.TransactionCase):
def test_validate_national_registry_number(self):
partner_id_category = self.env.ref(
"l10n_be_partner_identification."
"l10n_be_national_registry_number_category"
)
partner_1 = self.env.ref("base.res_partner_1")
# born before 2000
partner_1.write(
{
"id_numbers": [
(
0,
0,
{
"name": "85.01.01-002.14",
"category_id": partner_id_category.id,
},
)
]
}
)
id_number = partner_1.id_numbers[0]
self.assertEqual(id_number.name, "85.01.01-002.14")
# born after 2000
id_number.write(
{"name": "08.03.25-264.77", "category_id": partner_id_category.id}
)
self.assertEqual(id_number.name, "08.03.25-264.77")
with self.assertRaises(ValidationError), self.env.cr.savepoint():
# check invalid for a person born before 2000
id_number.name = "85.01.01-002.03"
with self.assertRaises(ValidationError), self.env.cr.savepoint():
# check invalid for a person born after 2000
id_number.name = "07.01.16-234.52"

def test_validate_id_card(self):
partner_id_category = self.env.ref(
"l10n_be_partner_identification." "l10n_be_id_card_category"
)
partner_1 = self.env.ref("base.res_partner_1")
# born before 2000
partner_1.write(
{
"id_numbers": [
(
0,
0,
{
"name": "000-0000000-97",
"category_id": partner_id_category.id,
},
)
]
}
)
id_number = partner_1.id_numbers[0]
self.assertEqual(id_number.name, "000-0000000-97")
# born after 2000
id_number.write(
{"name": "000-0000001-01", "category_id": partner_id_category.id}
)
self.assertEqual(id_number.name, "000-0000001-01")
with self.assertRaises(ValidationError), self.env.cr.savepoint():
# check invalid id number
id_number.name = "000-0000001-02"
6 changes: 6 additions & 0 deletions setup/l10n_be_partner_identification/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,
)
Loading