From 6391b0f585cc16467843d5e53ecdf2874368b42e Mon Sep 17 00:00:00 2001 From: Maxime Franco Date: Wed, 27 Sep 2023 10:36:32 +0200 Subject: [PATCH 1/2] [FIX] hr_employee_firstname - Updating the employee with the same name should not modify the firstname and lastname column --- hr_employee_firstname/models/hr_employee.py | 6 ++++-- hr_employee_firstname/tests/test_hr_employee_firstname.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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") From dadb3608113c2cd7d34ccfadda6ce8c958236d3b Mon Sep 17 00:00:00 2001 From: Maxime Franco Date: Wed, 27 Sep 2023 10:40:52 +0200 Subject: [PATCH 2/2] [FIX] hr_employee_lastnames - Updating the employee with the same name should not modify firstname lastname and lastname2 fields --- hr_employee_lastnames/models/hr_employee.py | 10 ++++++---- .../tests/test_hr_employee_lastnames.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) 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, "")