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>
36 lines
2.1 KiB
Python
36 lines
2.1 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.tests import TransactionCase
|
|
|
|
|
|
class TestResUsers(TransactionCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
cls.users = cls.env["res.users"].create([
|
|
{'name': 'Jean', 'login': 'jean@mail.com', 'password': 'jean@mail.com'},
|
|
{'name': 'Jean-Paul', 'login': 'jean-paul@mail.com', 'password': 'jean-paul@mail.com'},
|
|
{'name': 'Jean-Jacques', 'login': 'jean-jacques@mail.com', 'password': 'jean-jacques@mail.com'},
|
|
{'name': 'Georges', 'login': 'georges@mail.com', 'password': 'georges@mail.com'},
|
|
{'name': 'Claude', 'login': 'claude@mail.com', 'password': 'claude@mail.com'},
|
|
{'name': 'Pascal', 'login': 'pascal@mail.com', 'password': 'pascal@mail.com'},
|
|
])
|
|
|
|
def test_name_search(self):
|
|
""" Test name search with self assign feature """
|
|
ResUsers = self.env['res.users']
|
|
jean = self.users[0]
|
|
user_ids = ResUsers.with_user(jean)._name_search('')
|
|
self.assertEqual(jean.id, user_ids[0], "The current user, Jean, should be the first in the result.")
|
|
user_ids = ResUsers.with_user(jean)._name_search('Claude')
|
|
self.assertNotIn(jean.id, user_ids, "The current user, Jean, should not be in the result because his name does not fit the condition.")
|
|
pascal = self.users[-1]
|
|
user_ids = ResUsers.with_user(pascal)._name_search('')
|
|
self.assertEqual(pascal.id, user_ids[0], "The current user, Pascal, should be the first in the result.")
|
|
user_ids = ResUsers.with_user(pascal)._name_search('', limit=3)
|
|
self.assertEqual(pascal.id, user_ids[0], "The current user, Pascal, should be the first in the result.")
|
|
self.assertEqual(len(user_ids), 3, "The number of results found should still respect the limit set.")
|
|
jean_paul = self.users[1]
|
|
user_ids = ResUsers.with_user(jean_paul)._name_search('Jean')
|
|
self.assertEqual(jean_paul.id, user_ids[0], "The current user, Jean-Paul, should be the first in the result")
|