diff --git a/addons/hr/models/hr_employee.py b/addons/hr/models/hr_employee.py index 651773d232e..d033800c665 100644 --- a/addons/hr/models/hr_employee.py +++ b/addons/hr/models/hr_employee.py @@ -7,6 +7,7 @@ from string import digits from werkzeug.urls import url_encode from odoo import api, fields, models, _ +from odoo.osv.query import Query from odoo.exceptions import ValidationError, AccessError from odoo.modules.module import get_module_resource @@ -163,7 +164,11 @@ class HrEmployeePrivate(models.Model): """ if self.check_access_rights('read', raise_exception=False): return super(HrEmployeePrivate, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid) - return self.env['hr.employee.public']._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid) + ids = self.env['hr.employee.public']._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid) + if not count and isinstance(ids, Query): + # the result is expected from this table, so we should link tables + ids = super(HrEmployeePrivate, self.sudo())._search([('id', 'in', ids)]) + return ids def get_formview_id(self, access_uid=None): """ Override this method in order to redirect many2one towards the right model depending on access_uid """ diff --git a/addons/hr/tests/test_self_user_access.py b/addons/hr/tests/test_self_user_access.py index c4d94831da8..37aa30e00b1 100644 --- a/addons/hr/tests/test_self_user_access.py +++ b/addons/hr/tests/test_self_user_access.py @@ -185,3 +185,7 @@ class TestSelfAccessRights(TestHrCommon): for f in self.self_protected_fields_user: with self.assertRaises(AccessError): self.hubert.with_user(self.richard).write({f: 'dummy'}) + + def testSearchUserEMployee(self): + # Searching user based on employee_id field should not raise bad query error + self.env['res.users'].with_user(self.richard).search([('employee_id', 'ilike', 'Hubert')])