[FIX] hr: Fix automatic employee creation
Introduced by #85428 closes odoo/odoo#99672 X-original-commit: e6cef5ab9ec189f1f0b86e21a1400859f021ba06 Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
This commit is contained in:
committed by
Yannick Tivisse
parent
8003310ccc
commit
3dada389d4
@@ -140,8 +140,8 @@ class User(models.Model):
|
||||
employee_type = fields.Selection(related='employee_id.employee_type', readonly=False, related_sudo=False)
|
||||
employee_resource_calendar_id = fields.Many2one(related='employee_id.resource_calendar_id', string="Employee's Working Hours", readonly=True)
|
||||
|
||||
create_employee = fields.Boolean(store=False, default=True, string="Technical field, whether to create an employee")
|
||||
create_employee_id = fields.Many2one('hr.employee', store=False, string="Technical field, bind user to this employee on create")
|
||||
create_employee = fields.Boolean(store=False, default=True, copy=False, string="Technical field, whether to create an employee")
|
||||
create_employee_id = fields.Many2one('hr.employee', store=False, copy=False, string="Technical field, bind user to this employee on create")
|
||||
|
||||
can_edit = fields.Boolean(compute='_compute_can_edit')
|
||||
is_system = fields.Boolean(compute="_compute_is_system")
|
||||
|
||||
@@ -119,3 +119,43 @@ class TestHrEmployee(TestHrCommon):
|
||||
self.assertTrue(emp_sub_sub.member_of_department)
|
||||
self.assertFalse(emp_other.member_of_department)
|
||||
self.assertFalse(emp_parent.member_of_department)
|
||||
|
||||
def test_employee_create_from_user(self):
|
||||
employee = self.env['hr.employee'].create({
|
||||
'name': 'Test User 3 - employee'
|
||||
})
|
||||
user_1, user_2, user_3 = self.env['res.users'].create([
|
||||
{
|
||||
'name': 'Test User',
|
||||
'login': 'test_user',
|
||||
'email': 'test_user@odoo.com',
|
||||
},
|
||||
{
|
||||
'name': 'Test User 2',
|
||||
'login': 'test_user_2',
|
||||
'email': 'test_user_2@odoo.com',
|
||||
'create_employee': True,
|
||||
},
|
||||
{
|
||||
'name': 'Test User 3',
|
||||
'login': 'test_user_3',
|
||||
'email': 'test_user_3@odoo.com',
|
||||
'create_employee_id': employee.id,
|
||||
},
|
||||
])
|
||||
# Test that creating an user does not create an employee by default
|
||||
self.assertFalse(user_1.employee_id)
|
||||
# Test that setting create_employee does create the associated employee
|
||||
self.assertTrue(user_2.employee_id)
|
||||
# Test that creating an user with a given employee associates the employee correctly
|
||||
self.assertEqual(user_3.employee_id, employee)
|
||||
|
||||
def test_employee_create_from_signup(self):
|
||||
# Test that an employee is not created when signin up on the website
|
||||
self.env['res.users'].signup({
|
||||
'name': 'Test User',
|
||||
'login': 'test_user',
|
||||
'email': 'test_user@odoo.com',
|
||||
'password': 'test_user_password',
|
||||
})
|
||||
self.assertFalse(self.env['res.users'].search([('login', '=', 'test_user')]).employee_id)
|
||||
|
||||
Reference in New Issue
Block a user