Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] hr_employee_firstname and hr_employee_lastnames #1283

Closed
Closed
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
6 changes: 4 additions & 2 deletions hr_employee_firstname/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def _prepare_vals_on_write_firstname_lastname(self, vals):
firstname = self.firstname
vals["name"] = self._get_name(lastname, firstname)
elif vals.get("name"):
vals["lastname"] = self.split_name(vals["name"])["lastname"]
vals["firstname"] = self.split_name(vals["name"])["firstname"]
for rec in self:
if not rec.name or rec.name != vals.get("name"):
vals["lastname"] = self.split_name(vals["name"])["lastname"]
vals["firstname"] = self.split_name(vals["name"])["firstname"]

@api.model
def _get_whitespace_cleaned_name(self, name, comma=False):
Expand Down
8 changes: 8 additions & 0 deletions hr_employee_firstname/tests/test_hr_employee_firstname.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,11 @@ def test_change_name_with_space_with_set_last_first_comma(self):

self.assertEqual(self.employee1_id.firstname, "Jean-Pierre")
self.assertEqual(self.employee1_id.lastname, "Carnaud-Eyck")

def test_change_name_with_the_same_name(self):
self.employee1_id.write(
{"firstname": "Maxime Françis", "lastname": "Patrick Dubois"}
)
self.employee1_id.write({"name": "Maxime Françis Patrick Dubois"})
self.assertEqual(self.employee1_id.firstname, "Maxime Françis")
self.assertEqual(self.employee1_id.lastname, "Patrick Dubois")
10 changes: 6 additions & 4 deletions hr_employee_lastnames/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ def _prepare_vals_on_write_firstname_lastname(self, vals):
lastname2 = self.lastname2
vals["name"] = self._get_name_lastnames(lastname, firstname, lastname2)
elif vals.get("name"):
name_splitted = self.split_name(vals["name"])
vals["lastname"] = name_splitted["lastname"]
vals["firstname"] = name_splitted["firstname"]
vals["lastname2"] = name_splitted["lastname2"]
for rec in self:
if rec.name != vals.get("name"):
name_splitted = self.split_name(vals["name"])
vals["lastname"] = name_splitted["lastname"]
vals["firstname"] = name_splitted["firstname"]
vals["lastname2"] = name_splitted["lastname2"]
return res

def _update_partner_firstname(self):
Expand Down
13 changes: 13 additions & 0 deletions hr_employee_lastnames/tests/test_hr_employee_lastnames.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,16 @@ def test_change_lastname_with_set_last_first_comma(self):
self.employee1_id.refresh()

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

def test_change_name_with_the_same_name(self):
self.employee1_id.write(
{
"firstname": "Maxime Françis Patrick",
"lastname": "Dubois",
"lastname2": "",
}
)
self.employee1_id.write({"name": "Maxime Françis Patrick Dubois"})
self.assertEqual(self.employee1_id.firstname, "Maxime Françis Patrick")
self.assertEqual(self.employee1_id.lastname, "Dubois")
self.assertEqual(self.employee1_id.lastname2, "")
Loading