Skip to content

Commit

Permalink
[IMP] l10n_nl_partner_name: allow to configure infixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Oct 1, 2024
1 parent f131cf2 commit 31b33a0
Show file tree
Hide file tree
Showing 5 changed files with 505 additions and 2 deletions.
17 changes: 17 additions & 0 deletions l10n_nl_partner_name/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ Use Dutch conventions for partner names:
.. contents::
:local:

Configuration
=============

The module relies on a list of known infixes to get the parsing right:

van, der, den, op, ter, de, v/d, d', 't, te

Also any combination, so *op den*, *van der* etc will also be
recognized.

If you need a different set of infixes, set system parameter
``l10n_nl_partner_name_infixes`` to a comma separated list like

infix1,infix2,etc

Note this replaces the above list.

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

Expand Down
21 changes: 19 additions & 2 deletions l10n_nl_partner_name/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class ResPartner(models.Model):
"""Extend res.partner with extra fields for Dutch names."""

_inherit = "res.partner"
_l10n_nl_partner_name_infixes = ("van", "der", "den", "op", "ter", "de", "v/d")

initials = fields.Char()
infix = fields.Char()
Expand Down Expand Up @@ -41,6 +40,7 @@ def _get_inverse_name(self, name, is_company=False):
def add_token(key, value):
result[key] += (result[key] and " " or "") + value

infixes = self._l10n_nl_partner_name_infixes()
result = dict.fromkeys(("firstname", "lastname", "initials", "infix"), "")
tokens = (name or "").split()
while len(tokens) > 1:
Expand All @@ -49,7 +49,12 @@ def add_token(key, value):
add_token("initials", token)
elif token[:1] == "(" and token[-1:] == ")":
add_token("initials", token[1:-1])
elif token.lower() in self._l10n_nl_partner_name_infixes:
elif (
len(tokens) and " ".join([token.lower(), tokens[0].lower()]) in infixes
):
add_token("infix", " ".join([token.lower(), tokens[0].lower()]))
tokens.pop(0)
elif token.lower() in infixes:
add_token("infix", token)
elif result["infix"]:
tokens.insert(0, token)
Expand All @@ -58,3 +63,15 @@ def add_token(key, value):
add_token("firstname", token)
result["lastname"] = " ".join(tokens)
return result

def _l10n_nl_partner_name_infixes(self):
return tuple(
map(
str.strip,
self.env["ir.config_parameter"]
.get_param(
"l10n_nl_partner_name_infixes", "van,der,den,op,ter,de,v/d,d','t,te"
)
.split(","),
)
)
11 changes: 11 additions & 0 deletions l10n_nl_partner_name/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The module relies on a list of known infixes to get the parsing right:

van, der, den, op, ter, de, v/d, d', 't, te

Also any combination, so *op den*, *van der* etc will also be recognized.

If you need a different set of infixes, set system parameter `l10n_nl_partner_name_infixes` to a comma separated list like

infix1,infix2,etc

Note this replaces the above list.
Loading

0 comments on commit 31b33a0

Please sign in to comment.