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
22 changes: 18 additions & 4 deletions hr_employee_second_lastname/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ HR Employee First Name and Two Last Names

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to add firstname and lastnames (Father an Mother
Last Name) in employee form, and concatenate both in name field.
This module allows you to add firstname and lastnames (Father and Mother
Last Name) in employee form, and chooses how to concatenate them into
the name field using various available formats.

**Table of contents**

Expand All @@ -40,10 +41,20 @@ Usage
=====

1. Go to *Employees*

2. On the employee form view you will have 3 separate fields, one for
Firstname, second for Lastname, both required and Mother's Last Name
(optional).

3. Go to *Settings → General Settings → Employee Names Order* to choose
how the full name is composed from those parts:

- **Firstname Lastname** (e.g. *Manuel Fernandez Gonzalez*)
- **Lastname Firstname** (e.g. *Fernandez Gonzalez Manuel*)
- **Lastname, Firstname** (e.g. *Fernandez Gonzalez, Manuel*)
- **Lastname, Firstname SecondLastname** (e.g. *Fernandez, Manuel
Gonzalez*)

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

Expand All @@ -65,8 +76,11 @@ Authors
Contributors
------------

- Luis Escobar <lescobar@vauxoo.com>
- Hugo Adan <hugo@vauxoo.com>
- Luis Escobar <lescobar@vauxoo.com>
- Hugo Adan <hugo@vauxoo.com>
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__

- Bhavesh Heliconia

Maintainers
-----------
Expand Down
25 changes: 25 additions & 0 deletions hr_employee_second_lastname/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def _get_name_lastnames(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 @@ -97,6 +107,21 @@ def _get_inverse_name(self, name):
return result

order = self._get_names_order()

if order == "last_first_comma2":
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 not put this algorithm in _get_inverse_name.

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.

Could you please elaborate on what you meant? I think I've already placed this logic inside _get_inverse_name. Maybe I'm missing something or misunderstanding your point.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I mean, in the "original function", not the overloaded one.

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.

We can't because 'lastname2' field is introduced in 'hr_employee_second_lastname' module and we've used this field in this new name format

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

indeed !

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.

Thanks for confirming 🙂

# Expected input: "Lastname, Firstname SecondLastname"
# Split on comma first to isolate 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))

if order in ("first_last", "last_first_comma"):
Expand Down
2 changes: 2 additions & 0 deletions hr_employee_second_lastname/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- Luis Escobar \<<lescobar@vauxoo.com>\>
- Hugo Adan \<<hugo@vauxoo.com>\>
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
- Bhavesh Heliconia
5 changes: 3 additions & 2 deletions hr_employee_second_lastname/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
This module allows you to add firstname and lastnames (Father an Mother
Last Name) in employee form, and concatenate both in name field.
This module allows you to add firstname and lastnames (Father and Mother
Last Name) in employee form, and chooses how to concatenate them into the
name field using various available formats.
7 changes: 7 additions & 0 deletions hr_employee_second_lastname/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
2. On the employee form view you will have 3 separate fields, one for
Firstname, second for Lastname, both required and Mother's Last Name
(optional).
3. Go to *Settings → General Settings → Employee Names Order* to choose how the
full name is composed from those parts:

- **Firstname Lastname** (e.g. *Manuel Fernandez Gonzalez*)
- **Lastname Firstname** (e.g. *Fernandez Gonzalez Manuel*)
- **Lastname, Firstname** (e.g. *Fernandez Gonzalez, Manuel*)
- **Lastname, Firstname SecondLastname** (e.g. *Fernandez, Manuel Gonzalez*)
18 changes: 16 additions & 2 deletions hr_employee_second_lastname/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ <h1 class="title">HR Employee First Name and Two Last Names</h1>
!! source digest: sha256:52c05367ec1f1cb684bdfc69407a7b0da9ab5435d8915013fd942ecc567cd625
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/hr/tree/18.0/hr_employee_second_lastname"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-18-0/hr-18-0-hr_employee_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/hr&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 allows you to add firstname and lastnames (Father an Mother
Last Name) in employee form, and concatenate both in name field.</p>
<p>This module allows you to add firstname and lastnames (Father and Mother
Last Name) in employee form, and chooses how to concatenate them into
the name field using various available formats.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -392,6 +393,15 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<li>On the employee form view you will have 3 separate fields, one for
Firstname, second for Lastname, both required and Mother’s Last Name
(optional).</li>
<li>Go to <em>Settings → General Settings → Employee Names Order</em> to choose
how the full name is composed from those parts:<ul>
<li><strong>Firstname Lastname</strong> (e.g. <em>Manuel Fernandez Gonzalez</em>)</li>
<li><strong>Lastname Firstname</strong> (e.g. <em>Fernandez Gonzalez Manuel</em>)</li>
<li><strong>Lastname, Firstname</strong> (e.g. <em>Fernandez Gonzalez, Manuel</em>)</li>
<li><strong>Lastname, Firstname SecondLastname</strong> (e.g. <em>Fernandez, Manuel
Gonzalez</em>)</li>
</ul>
</li>
</ol>
</div>
<div class="section" id="bug-tracker">
Expand All @@ -415,6 +425,10 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Luis Escobar &lt;<a class="reference external" href="mailto:lescobar&#64;vauxoo.com">lescobar&#64;vauxoo.com</a>&gt;</li>
<li>Hugo Adan &lt;<a class="reference external" href="mailto:hugo&#64;vauxoo.com">hugo&#64;vauxoo.com</a>&gt;</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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,54 @@ def test_change_lastname_with_set_last_first_comma(self):
self.employee1_id.invalidate_recordset()

self.assertEqual(self.employee1_id.name, "Lopez Gonzalez, Manuel")

def test_change_lastname_with_set_last_first_comma2(self):
self.env["ir.config_parameter"].sudo().set_param(
"employee_names_order", "last_first_comma2"
)
self.employee1_id.write({"lastname": "Lopez"})
self.employee1_id.invalidate_recordset()

self.assertEqual(self.employee1_id.name, "Lopez, Manuel Gonzalez")

def test_change_name_with_set_last_first_comma2(self):
self.env["ir.config_parameter"].sudo().set_param(
"employee_names_order", "last_first_comma2"
)
self.employee1_id.write({"name": "Martinez, Pedro Torres"})
self.employee1_id.invalidate_recordset()

self.assertEqual(self.employee1_id.firstname, "Pedro")
self.assertEqual(self.employee1_id.lastname, "Martinez")
self.assertEqual(self.employee1_id.lastname2, "Torres")

def test_change_name_with_set_last_first_comma2_no_lastname2(self):
self.env["ir.config_parameter"].sudo().set_param(
"employee_names_order", "last_first_comma2"
)
self.employee1_id.write({"name": "Martinez, Pedro"})
self.employee1_id.invalidate_recordset()

self.assertEqual(self.employee1_id.firstname, "Pedro")
self.assertEqual(self.employee1_id.lastname, "Martinez")
self.assertEqual(self.employee1_id.lastname2, False)

def test_change_name_with_set_last_first_comma2_only_lastname(self):
self.env["ir.config_parameter"].sudo().set_param(
"employee_names_order", "last_first_comma2"
)
self.employee1_id.write({"name": "Martinez"})
self.employee1_id.invalidate_recordset()

self.assertEqual(self.employee1_id.lastname, "Martinez")

def test_change_name_with_set_last_first_comma2_extra_spaces(self):
self.env["ir.config_parameter"].sudo().set_param(
"employee_names_order", "last_first_comma2"
)
self.employee1_id.write({"name": " Martinez , Pedro Torres "})
self.employee1_id.invalidate_recordset()

self.assertEqual(self.employee1_id.firstname, "Pedro")
self.assertEqual(self.employee1_id.lastname, "Martinez")
self.assertEqual(self.employee1_id.lastname2, "Torres")
Loading