diff --git a/hr_employee_second_lastname/__manifest__.py b/hr_employee_second_lastname/__manifest__.py index b6216e521b9a..083ad630a6a0 100644 --- a/hr_employee_second_lastname/__manifest__.py +++ b/hr_employee_second_lastname/__manifest__.py @@ -1,7 +1,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "HR Employee First Name and Two Last Names", - "version": "16.0.1.0.2", + "version": "17.0.1.0.0", "author": "Vauxoo, Odoo Community Association (OCA)", "maintainers": ["luisg123v"], "website": "https://github.com/OCA/hr", diff --git a/hr_employee_second_lastname/hooks.py b/hr_employee_second_lastname/hooks.py index 0ab9bacab293..dca96c41fe70 100644 --- a/hr_employee_second_lastname/hooks.py +++ b/hr_employee_second_lastname/hooks.py @@ -1,8 +1,4 @@ -from odoo import SUPERUSER_ID -from odoo.api import Environment - - -def post_init_hook(cr, _): +def post_init_hook(env): # This SQL statement is necessary to call _install_employee_lastnames() and # set name fields correctly. # @@ -23,7 +19,6 @@ def post_init_hook(cr, _): # firstname = 'John' # lastname = 'Peterson' # lastname2 = 'Clinton' - cr.execute("UPDATE hr_employee SET firstname = NULL, lastname = NULL") - env = Environment(cr, SUPERUSER_ID, {}) + env.cr.execute("UPDATE hr_employee SET firstname = NULL, lastname = NULL") env["hr.employee"]._install_employee_lastnames() env["ir.config_parameter"].sudo().set_param("employee_names_order", "first_last") diff --git a/hr_employee_second_lastname/models/hr_employee.py b/hr_employee_second_lastname/models/hr_employee.py index 7f999b08dae9..edf085ccdda7 100644 --- a/hr_employee_second_lastname/models/hr_employee.py +++ b/hr_employee_second_lastname/models/hr_employee.py @@ -36,7 +36,7 @@ def _get_name_lastnames(self, lastname, firstname, lastname2=None): def _prepare_vals_on_create_firstname_lastname(self, vals): values = vals.copy() - res = super(HrEmployee, self)._prepare_vals_on_create_firstname_lastname(values) + res = super()._prepare_vals_on_create_firstname_lastname(values) if any([field in vals for field in ("firstname", "lastname", "lastname2")]): vals["name"] = self._get_name_lastnames( vals.get("lastname"), vals.get("firstname"), vals.get("lastname2") @@ -50,7 +50,7 @@ def _prepare_vals_on_create_firstname_lastname(self, vals): def _prepare_vals_on_write_firstname_lastname(self, vals): values = vals.copy() - res = super(HrEmployee, self)._prepare_vals_on_write_firstname_lastname(values) + res = super()._prepare_vals_on_write_firstname_lastname(values) if any([field in vals for field in ("firstname", "lastname", "lastname2")]): if "lastname" in vals: lastname = vals["lastname"] @@ -97,7 +97,7 @@ def _get_inverse_name(self, name): return result order = self._get_names_order() - result.update(super(HrEmployee, self)._get_inverse_name(name)) + result.update(super()._get_inverse_name(name)) if order in ("first_last", "last_first_comma"): parts = self._split_part("lastname", result) diff --git a/hr_employee_second_lastname/tests/test_hr_employee_lastnames.py b/hr_employee_second_lastname/tests/test_hr_employee_lastnames.py index 2cb1d515de66..b792c9bf12af 100644 --- a/hr_employee_second_lastname/tests/test_hr_employee_lastnames.py +++ b/hr_employee_second_lastname/tests/test_hr_employee_lastnames.py @@ -1,10 +1,11 @@ from odoo import exceptions from odoo.tests.common import TransactionCase +from odoo.tools import submap class TestEmployeeLastnames(TransactionCase): def setUp(self): - super(TestEmployeeLastnames, self).setUp() + super().setUp() self.env["ir.config_parameter"].sudo().set_param( "employee_names_order", "first_last" ) @@ -45,9 +46,18 @@ def test_get_name_lastnames(self): def test_onchange(self): """Validate the _get_name_lastnames method is not failing""" - field_onchange = self.employee_model.new({})._onchange_spec() - self.assertEqual(field_onchange.get("firstname"), "1") - self.assertEqual(field_onchange.get("lastname"), "1") + # Check that fields used to generate the name and also name field + # are empty before onchange + fields_spec = self.env["hr.employee"]._get_fields_spec() + self.assertEqual( + submap(fields_spec, ("firstname", "lastname", "lastname2", "name")), + { + "firstname": {}, + "lastname": {}, + "lastname2": {}, + "name": {}, + }, + ) values = { "firstname": "Pedro", "lastname": "Perez", @@ -61,7 +71,7 @@ def test_onchange(self): new_record = self.employee_model.new(values) updates = new_record.onchange( - values, ["firstname", "lastname", "lastname2"], field_onchange + values, ["firstname", "lastname", "lastname2"], fields_spec ) values.update(updates.get("value", {})) self.assertEqual(values["name"], "Pedro Perez Hernandez")