diff --git a/hr_employee_firstname/models/hr_employee.py b/hr_employee_firstname/models/hr_employee.py index c16baff7112..0cb7db6ad77 100644 --- a/hr_employee_firstname/models/hr_employee.py +++ b/hr_employee_firstname/models/hr_employee.py @@ -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): diff --git a/hr_employee_firstname/tests/test_hr_employee_firstname.py b/hr_employee_firstname/tests/test_hr_employee_firstname.py index dc872e8ddc4..65b832b5b41 100644 --- a/hr_employee_firstname/tests/test_hr_employee_firstname.py +++ b/hr_employee_firstname/tests/test_hr_employee_firstname.py @@ -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") diff --git a/hr_employee_lastnames/models/hr_employee.py b/hr_employee_lastnames/models/hr_employee.py index 7f999b08dae..e3cc7ecee95 100644 --- a/hr_employee_lastnames/models/hr_employee.py +++ b/hr_employee_lastnames/models/hr_employee.py @@ -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): diff --git a/hr_employee_lastnames/tests/test_hr_employee_lastnames.py b/hr_employee_lastnames/tests/test_hr_employee_lastnames.py index d730a4b0ef9..8a8f43f096a 100644 --- a/hr_employee_lastnames/tests/test_hr_employee_lastnames.py +++ b/hr_employee_lastnames/tests/test_hr_employee_lastnames.py @@ -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, "")