diff --git a/hr_employee_second_lastname/README.rst b/hr_employee_second_lastname/README.rst index 6db7517a715..b3333c868bf 100644 --- a/hr_employee_second_lastname/README.rst +++ b/hr_employee_second_lastname/README.rst @@ -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** @@ -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 =========== @@ -65,8 +76,11 @@ Authors Contributors ------------ -- Luis Escobar -- Hugo Adan +- Luis Escobar +- Hugo Adan +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia Maintainers ----------- diff --git a/hr_employee_second_lastname/models/hr_employee.py b/hr_employee_second_lastname/models/hr_employee.py index edf085ccdda..cf2840151c9 100644 --- a/hr_employee_second_lastname/models/hr_employee.py +++ b/hr_employee_second_lastname/models/hr_employee.py @@ -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) @@ -97,6 +107,21 @@ def _get_inverse_name(self, name): return result order = self._get_names_order() + + if order == "last_first_comma2": + # 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"): diff --git a/hr_employee_second_lastname/readme/CONTRIBUTORS.md b/hr_employee_second_lastname/readme/CONTRIBUTORS.md index 021f9de3f90..fa6a121e982 100644 --- a/hr_employee_second_lastname/readme/CONTRIBUTORS.md +++ b/hr_employee_second_lastname/readme/CONTRIBUTORS.md @@ -1,2 +1,4 @@ - Luis Escobar \<\> - Hugo Adan \<\> +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/hr_employee_second_lastname/readme/DESCRIPTION.md b/hr_employee_second_lastname/readme/DESCRIPTION.md index f8b51331199..a8aeeb0b72b 100644 --- a/hr_employee_second_lastname/readme/DESCRIPTION.md +++ b/hr_employee_second_lastname/readme/DESCRIPTION.md @@ -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. diff --git a/hr_employee_second_lastname/readme/USAGE.md b/hr_employee_second_lastname/readme/USAGE.md index 4f2fb890ecc..264388f956b 100644 --- a/hr_employee_second_lastname/readme/USAGE.md +++ b/hr_employee_second_lastname/readme/USAGE.md @@ -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*) diff --git a/hr_employee_second_lastname/static/description/index.html b/hr_employee_second_lastname/static/description/index.html index 864694cd816..951df1bc305 100644 --- a/hr_employee_second_lastname/static/description/index.html +++ b/hr_employee_second_lastname/static/description/index.html @@ -370,8 +370,9 @@

HR Employee First Name and Two Last Names

!! source digest: sha256:52c05367ec1f1cb684bdfc69407a7b0da9ab5435d8915013fd942ecc567cd625 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/hr Translate me on Weblate Try me on Runboat

-

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

    @@ -392,6 +393,15 @@

    Usage

  • 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).
  • +
  • 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)
    • +
    +
@@ -415,6 +425,10 @@

Contributors

diff --git a/hr_employee_second_lastname/tests/test_hr_employee_second_lastname.py b/hr_employee_second_lastname/tests/test_hr_employee_second_lastname.py index 8f1ff1eb329..c7341b8b50f 100644 --- a/hr_employee_second_lastname/tests/test_hr_employee_second_lastname.py +++ b/hr_employee_second_lastname/tests/test_hr_employee_second_lastname.py @@ -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")