Skip to content

Commit

Permalink
[MIG] l10n_nl_partner_name: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsirintanis committed Mar 25, 2024
1 parent a6b1a8b commit 0841728
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 34 deletions.
4 changes: 2 additions & 2 deletions l10n_nl_partner_name/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2017 Therp BV <https://therp.nl>
# Copyright 2017-24 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Dutch partner names",
"version": "12.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Therp BV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-netherlands",
"category": "Contact management",
Expand Down
27 changes: 2 additions & 25 deletions l10n_nl_partner_name/model/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Copyright 2017 Therp BV <https://therp.nl>
# Copyright 2017-24 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models

from odoo.addons.mail.models.mail_template import mako_safe_template_env


class ResPartner(models.Model):
"""Extend res.partner with extra fields for Dutch names."""
Expand All @@ -13,34 +11,13 @@ class ResPartner(models.Model):
initials = fields.Char()
infix = fields.Char()

@api.multi
@api.depends("firstname", "lastname", "initials", "infix")
def _compute_name(self):
for record in self:
record.name = record._get_computed_name(
record.lastname, record.firstname, record.initials, record.infix
)

@api.onchange("firstname", "lastname", "initials", "infix")
def _onchange_subnames(self):
return super(ResPartner, self)._onchange_subnames()

@api.model
def _get_computed_name(self, lastname, firstname, initials=None, infix=None):
name_template = mako_safe_template_env.from_string(
self.env.context.get(
"name_format",
"${firstname or initials or ''}"
"${(firstname or initials) and ' ' or ''}"
"${infix or ''}${infix and ' ' or ''}${lastname or ''}",
)
)
name = name_template.render(
{
"firstname": firstname,
"lastname": lastname,
"initials": initials,
"infix": infix,
}
)
return name if name else ""
return " ".join(p for p in (firstname, initials, infix, lastname) if p)
3 changes: 1 addition & 2 deletions l10n_nl_partner_name/tests/test_l10n_nl_partner_name.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Therp BV <https://therp.nl>
# Copyright 2016-24 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase

Expand All @@ -22,5 +22,4 @@ def test_l10n_nl_partner_name(self):
)
self.assertEqual(partner.firstname, "Willem-Alexander")
self.assertEqual(partner.lastname, "van Oranje-Nassau")
partner._onchange_subnames()
self.assertEqual(partner.name, "Willem-Alexander van Oranje-Nassau")
7 changes: 2 additions & 5 deletions l10n_nl_partner_name/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<record id="view_partner_simple_form_firstname" model="ir.ui.view">
<field name="name">res.partner.simplified.form.firstname</field>
<field name="model">res.partner</field>
<field
name="inherit_id"
ref="partner_firstname.view_partner_simple_form_firstname"
/>
<field name="inherit_id" ref="partner_firstname.view_partner_simple_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='firstname']/ancestor::group[1]" position="inside">
<div name="partner_name_dutch">
Expand Down Expand Up @@ -45,7 +42,7 @@
<record id="view_partner_form_firstname" model="ir.ui.view">
<field name="name">res.partner.form.firstname</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_firstname.view_partner_form_firstname" />
<field name="inherit_id" ref="partner_firstname.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='firstname']/ancestor::group[1]" position="inside">
<div name="partner_name_dutch">
Expand Down

0 comments on commit 0841728

Please sign in to comment.