Adds a new non stored field to make it easier to query all employees from the active user's department and it's children department(s). The result is guaranteed to always contain the active user's employee. task-2700231 closes odoo/odoo#81472 Related: odoo/enterprise#22724 Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
122 lines
4.6 KiB
Python
122 lines
4.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.tests import Form
|
|
from odoo.addons.hr.tests.common import TestHrCommon
|
|
|
|
|
|
class TestHrEmployee(TestHrCommon):
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.user_without_image = self.env['res.users'].create({
|
|
'name': 'Marc Demo',
|
|
'email': 'mark.brown23@example.com',
|
|
'image_1920': False,
|
|
'login': 'demo_1',
|
|
'password': 'demo_123'
|
|
})
|
|
self.employee_without_image = self.env['hr.employee'].create({
|
|
'user_id': self.user_without_image.id,
|
|
'image_1920': False
|
|
})
|
|
|
|
def test_employee_resource(self):
|
|
_tz = 'Pacific/Apia'
|
|
self.res_users_hr_officer.company_id.resource_calendar_id.tz = _tz
|
|
Employee = self.env['hr.employee'].with_user(self.res_users_hr_officer)
|
|
employee_form = Form(Employee)
|
|
employee_form.name = 'Raoul Grosbedon'
|
|
employee_form.work_email = 'raoul@example.com'
|
|
employee = employee_form.save()
|
|
self.assertEqual(employee.tz, _tz)
|
|
|
|
def test_employee_from_user(self):
|
|
_tz = 'Pacific/Apia'
|
|
_tz2 = 'America/Tijuana'
|
|
self.res_users_hr_officer.company_id.resource_calendar_id.tz = _tz
|
|
self.res_users_hr_officer.tz = _tz2
|
|
Employee = self.env['hr.employee'].with_user(self.res_users_hr_officer)
|
|
employee_form = Form(Employee)
|
|
employee_form.name = 'Raoul Grosbedon'
|
|
employee_form.work_email = 'raoul@example.com'
|
|
employee_form.user_id = self.res_users_hr_officer
|
|
employee = employee_form.save()
|
|
self.assertEqual(employee.name, 'Raoul Grosbedon')
|
|
self.assertEqual(employee.work_email, self.res_users_hr_officer.email)
|
|
self.assertEqual(employee.tz, self.res_users_hr_officer.tz)
|
|
|
|
def test_employee_from_user_tz_no_reset(self):
|
|
_tz = 'Pacific/Apia'
|
|
self.res_users_hr_officer.tz = False
|
|
Employee = self.env['hr.employee'].with_user(self.res_users_hr_officer)
|
|
employee_form = Form(Employee)
|
|
employee_form.name = 'Raoul Grosbedon'
|
|
employee_form.work_email = 'raoul@example.com'
|
|
employee_form.tz = _tz
|
|
employee_form.user_id = self.res_users_hr_officer
|
|
employee = employee_form.save()
|
|
self.assertEqual(employee.name, 'Raoul Grosbedon')
|
|
self.assertEqual(employee.work_email, self.res_users_hr_officer.email)
|
|
self.assertEqual(employee.tz, _tz)
|
|
|
|
def test_employee_has_avatar_even_if_it_has_no_image(self):
|
|
self.assertTrue(self.employee_without_image.avatar_128)
|
|
self.assertTrue(self.employee_without_image.avatar_256)
|
|
self.assertTrue(self.employee_without_image.avatar_512)
|
|
self.assertTrue(self.employee_without_image.avatar_1024)
|
|
self.assertTrue(self.employee_without_image.avatar_1920)
|
|
|
|
def test_employee_has_same_avatar_as_corresponding_user(self):
|
|
self.assertEqual(self.employee_without_image.avatar_1920, self.user_without_image.avatar_1920)
|
|
|
|
def test_employee_member_of_department(self):
|
|
dept, dept_sub, dept_sub_sub, dept_other, dept_parent = self.env['hr.department'].create([
|
|
{
|
|
'name': 'main',
|
|
},
|
|
{
|
|
'name': 'sub',
|
|
},
|
|
{
|
|
'name': 'sub-sub',
|
|
},
|
|
{
|
|
'name': 'other',
|
|
},
|
|
{
|
|
'name': 'parent',
|
|
},
|
|
])
|
|
dept_sub.parent_id = dept
|
|
dept_sub_sub.parent_id = dept_sub
|
|
dept.parent_id = dept_parent
|
|
emp, emp_sub, emp_sub_sub, emp_other, emp_parent = self.env['hr.employee'].with_user(self.res_users_hr_officer).create([
|
|
{
|
|
'name': 'employee',
|
|
'department_id': dept.id,
|
|
},
|
|
{
|
|
'name': 'employee sub',
|
|
'department_id': dept_sub.id,
|
|
},
|
|
{
|
|
'name': 'employee sub sub',
|
|
'department_id': dept_sub_sub.id,
|
|
},
|
|
{
|
|
'name': 'employee other',
|
|
'department_id': dept_other.id,
|
|
},
|
|
{
|
|
'name': 'employee parent',
|
|
'department_id': dept_parent.id,
|
|
},
|
|
])
|
|
self.res_users_hr_officer.employee_id = emp
|
|
self.assertTrue(emp.member_of_department)
|
|
self.assertTrue(emp_sub.member_of_department)
|
|
self.assertTrue(emp_sub_sub.member_of_department)
|
|
self.assertFalse(emp_other.member_of_department)
|
|
self.assertFalse(emp_parent.member_of_department)
|