Before this commit, when the user wants to self assign to a task for instance, he has to write his name to be able to select himself. This commit displays the current user first in the result of `name_search` (the method called by relational widgets in JS). If the current user does not satisfy the search condition then he will not be in the result of the `name_search`. task-3291745 closes odoo/odoo#121146 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
28 lines
942 B
Python
28 lines
942 B
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, models
|
|
from odoo.osv import expression
|
|
|
|
|
|
class ResUsers(models.Model):
|
|
_inherit = "res.users"
|
|
|
|
@api.model
|
|
def _name_search(self, name, domain=None, operator='ilike', limit=None, order=None):
|
|
user_ids = list(super()._name_search(name, domain, operator, limit, order))
|
|
if self._uid in user_ids:
|
|
if user_ids.index(self._uid) != 0:
|
|
user_ids.remove(self._uid)
|
|
user_ids.insert(0, self._uid)
|
|
elif limit and len(user_ids) == limit:
|
|
new_user_ids = super()._name_search(
|
|
name,
|
|
expression.AND([domain or [], [('id', '=', self._uid)]]),
|
|
operator,
|
|
limit=1,
|
|
)
|
|
if new_user_ids:
|
|
user_ids.pop()
|
|
user_ids.insert(0, self._uid)
|
|
return user_ids
|