Skip to content

Commit

Permalink
[FIX] hr_employee_lastnames - Updating the employee with the same nam…
Browse files Browse the repository at this point in the history
…e should not modify firstname lastname and lastname2 fields
  • Loading branch information
FrancoMaxime committed Sep 27, 2023
1 parent 6391b0f commit dadb360
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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, "")

0 comments on commit dadb360

Please sign in to comment.