Skip to content

Commit

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

0 comments on commit 6391b0f

Please sign in to comment.