Skip to content
Open
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
11 changes: 6 additions & 5 deletions partner_second_lastname/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

========================
Partner second last name
========================
Expand All @@ -17,7 +13,7 @@ Partner second last name
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github
Expand Down Expand Up @@ -59,6 +55,8 @@ Settings > Configuration > General settings:
Robert'
- Firstname Lastname SecondLastname: For example 'Robert Anderson
Lavarge'
- Lastname, Firstname SecondLastname: For example 'Anderson, Robert
Lavarge'

After applying the changes, you can recalculate all partners name
clicking "Recalculate names" button. Note: This process could take so
Expand Down Expand Up @@ -113,6 +111,9 @@ Contributors
- Nikul Chaudhary <nikulchaudhary2112@gmail.com>
- Manuel Regidor <manuel.regidor@sygel.es>
- Eduardo de Miguel (``Moduon <https://www.moduon.team/>``\ \_\_)
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__

- Bhavesh Heliconia

Maintainers
-----------
Expand Down
5 changes: 4 additions & 1 deletion partner_second_lastname/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def _partner_names_order_selection(self):
"last_first_comma": "Lastname SecondLastname, Firstname",
"first_last": "Firstname Lastname SecondLastname",
}
return [(k, new_labels[k]) if k in new_labels else (k, v) for k, v in options]
result = [(k, new_labels[k]) if k in new_labels else (k, v) for k, v in options]
# Separate format where only the first lastname is followed by a comma
result.append(("last_first_comma2", "Lastname, Firstname SecondLastname"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't you add it directly to the new_labels dict?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luisDIXMIT Here, if we add it to 'new_labels' dict, then it won't get added in 'result' as we're looping on 'options' and 'options' don't have 'last_first_comma2', so we've added it separately afterwards.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks for explaining me!

return result

def _partners_for_recalculating(self):
return self.env["res.partner"].search(
Expand Down
37 changes: 33 additions & 4 deletions partner_second_lastname/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ def name_fields_in_vals(self, vals):
return super().name_fields_in_vals(vals) or vals.get("lastname2")

def get_extra_default_copy_values(self):
"""Override to add '(copy)' suffix to lastname2 instead of lastname."""
if self._get_names_order() == "first_last":
"""Override to add '(copy)' suffix to lastname2 instead of lastname.

For formats where lastname2 is the trailing part of the displayed
name (first_last, last_first_comma2), the copy marker belongs there.
"""
if self._get_names_order() in ("first_last", "last_first_comma2"):
return {
"lastname2": _("%s (copy)", self.lastname2)
if self.lastname2
Expand All @@ -36,8 +40,8 @@ def get_extra_default_copy_values(self):
def _get_computed_name(self, lastname, firstname, lastname2=None):
"""Compute the name combined with the second lastname too.

We have 2 lastnames, so lastnames and firstname will be separated by a
comma.
We have 2 lastnames, so lastnames and firstname will be separated
differently depending on the configured name order.
"""
order = self._get_names_order()
names = list()
Expand All @@ -48,6 +52,16 @@ def _get_computed_name(self, lastname, firstname, lastname2=None):
names.append(lastname)
if lastname2:
names.append(lastname2)
elif order == "last_first_comma2":
# Format: "Lastname, Firstname SecondLastname"
if lastname:
names.append(lastname)
if names and (firstname or lastname2):
names[0] = names[0] + ","
if firstname:
names.append(firstname)
if lastname2:
names.append(lastname2)
else:
if lastname:
names.append(lastname)
Expand Down Expand Up @@ -100,6 +114,21 @@ def _get_inverse_name(self, name, is_company=False):
return result

order = self._get_names_order()

if order == "last_first_comma2":
# Expected input: "Lastname, Firstname SecondLastname"
# Split on comma to isolate the first lastname from the rest.
clean = self._get_whitespace_cleaned_name(name, comma=True)
parts = clean.split(",", 1)
result["lastname"] = parts[0].strip() or False
if len(parts) > 1:
rest = parts[1].strip()
rest_parts = rest.split(" ", 1)
result["firstname"] = rest_parts[0] or False
if len(rest_parts) > 1:
result["lastname2"] = rest_parts[1] or False
return result

result.update(super()._get_inverse_name(name, is_company))

if order in ("first_last", "last_first_comma"):
Expand Down
2 changes: 2 additions & 0 deletions partner_second_lastname/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Settings \> Configuration \> General settings:
Robert'
- Firstname Lastname SecondLastname: For example 'Robert Anderson
Lavarge'
- Lastname, Firstname SecondLastname: For example 'Anderson, Robert
Lavarge'

After applying the changes, you can recalculate all partners name
clicking "Recalculate names" button. Note: This process could take so
Expand Down
2 changes: 2 additions & 0 deletions partner_second_lastname/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
- Nikul Chaudhary \<<nikulchaudhary2112@gmail.com>\>
- Manuel Regidor \<<manuel.regidor@sygel.es>\>
- Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__)
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
- Bhavesh Heliconia
34 changes: 17 additions & 17 deletions partner_second_lastname/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Partner second last name</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="partner-second-last-name">
<h1 class="title">Partner second last name</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="partner-second-last-name">
<h1>Partner second last name</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8a3121a7c4a02d0dbdedd2cf4e4ba89afd32f9842b3865f72ac3c43f70b0a4ea
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/partner-contact/tree/18.0/partner_second_lastname"><img alt="OCA/partner-contact" src="https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/partner-contact-18-0/partner-contact-18-0-partner_second_lastname"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/partner-contact/tree/18.0/partner_second_lastname"><img alt="OCA/partner-contact" src="https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/partner-contact-18-0/partner-contact-18-0-partner_second_lastname"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to extend the functionality of
<tt class="docutils literal">partner_firstname</tt> to support having a second lastname for contact
partners.</p>
Expand All @@ -397,7 +392,7 @@ <h1>Partner second last name</h1>
</ul>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>You can configure some common name patterns for the inverse function in
Settings &gt; Configuration &gt; General settings:</p>
<ul class="simple">
Expand All @@ -407,6 +402,8 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
Robert’</li>
<li>Firstname Lastname SecondLastname: For example ‘Robert Anderson
Lavarge’</li>
<li>Lastname, Firstname SecondLastname: For example ‘Anderson, Robert
Lavarge’</li>
</ul>
<p>After applying the changes, you can recalculate all partners name
clicking “Recalculate names” button. Note: This process could take so
Expand All @@ -417,7 +414,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
methods can be overridden to change the format specified above.</p>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module, you need to:</p>
<ul class="simple">
<li>Edit any partner’s form.</li>
Expand All @@ -432,34 +429,38 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
fail for you easily in some corner cases.</p>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/partner-contact/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_second_lastname%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Jairo Llopis &lt;<a class="reference external" href="mailto:jairo.llopis&#64;tecnativa.com">jairo.llopis&#64;tecnativa.com</a>&gt;.</li>
<li>Antonio Espinosa.</li>
<li>Pedro M. Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;tecnativa.com">pedro.baeza&#64;tecnativa.com</a>&gt;.</li>
<li>Nikul Chaudhary &lt;<a class="reference external" href="mailto:nikulchaudhary2112&#64;gmail.com">nikulchaudhary2112&#64;gmail.com</a>&gt;</li>
<li>Manuel Regidor &lt;<a class="reference external" href="mailto:manuel.regidor&#64;sygel.es">manuel.regidor&#64;sygel.es</a>&gt;</li>
<li>Eduardo de Miguel (<tt class="docutils literal">Moduon <span class="pre">&lt;https://www.moduon.team/&gt;</span></tt>__)</li>
<li><a class="reference external" href="https://www.heliconia.io">Heliconia Solutions Pvt. Ltd.</a><ul>
<li>Bhavesh Heliconia</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -472,6 +473,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions partner_second_lastname/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ def test_first_last(self):
self.wizard.set_values()
self.wizard.action_recalculate_partners_name()
self.assertEqual(self.partner.name, "First Last Second")

def test_last_first_comma2(self):
self.wizard.partner_names_order = "last_first_comma2"
self.wizard.set_values()
self.wizard.action_recalculate_partners_name()
self.assertEqual(self.partner.name, "Last, First Second")
7 changes: 7 additions & 0 deletions partner_second_lastname/tests/test_multiple_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ def test_recalculate_names(self):
"last_first_comma",
f"{lastname} {lastname2}, {firstname}",
)
self.assert_name(
config_settings,
partner,
vals,
"last_first_comma2",
f"{lastname}, {firstname} {lastname2}",
)
25 changes: 25 additions & 0 deletions partner_second_lastname/tests/test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ def test_lastname_firstname_only_wo_comma(self):
"name": f"{self.lastname} {self.firstname}",
}

def test_firstname_last_comma2(self):
"""Create a person using the 'last_first_comma2' order.
Expected name format: Lastname, Firstname SecondLastname"""
self.env["ir.config_parameter"].set_param(
"partner_names_order", "last_first_comma2"
)
self.template = "%(last1)s, %(first)s %(last2)s"
self.params = {
"is_company": False,
"name": f"{self.lastname}, {self.firstname} {self.lastname2}",
}

def test_lastname_firstname_only_comma2(self):
"""Create a person with only lastname and firstname under the
'last_first_comma2' order, i.e. no second lastname provided."""
self.env["ir.config_parameter"].set_param(
"partner_names_order", "last_first_comma2"
)
self.lastname2 = False
self.template = "%(last1)s, %(first)s"
self.params = {
"is_company": False,
"name": f"{self.lastname}, {self.firstname}",
}

def test_separately(self):
"""Create a person setting separately all fields."""
self.params = {
Expand Down
Loading