[FIX] project: fix tag name search with none project in context

This commit fixes the name_search traceback on project tags when the
`project_id` in context is set to `False`.

Prior to commit odoo/odoo@05855b6b this check was still relevant since
the implementation used the ORM search method. Since this commit,
project_id must be an integer to be used in the SQL query.

Steps to reproduce:
- Open Project menu;
- Go to My Tasks menu;
- Create a new task;
- Open task;
- Click on Tags field.

Current Behavior:
```
  File "/home/src/odoo/odoo/models.py", line 1605, in name_search
    ids = self._name_search(name, args, operator, limit=limit)
  File "/home/src/odoo/addons/project/models/project.py", line 2756, in
  _name_search
    self.env.cr.execute(query, params)
  File "/home/src/odoo/odoo/sql_db.py", line 313, in execute
    res = self._obj.execute(query, params)
psycopg2.errors.UndefinedFunction: operator does not exist: integer =
boolean
LINE 9:                             ON task.project_id = false
                                                       ^
HINT:  No operator matches the given name and argument types. You might
       need to add explicit type casts.
```

Expected Behavior:
- No traceback and standard name_search behavior.

closes odoo/odoo#116006

X-original-commit: f21bd6f47a75f5d6cbd442f30ef7df221e6fec7d
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
Thibault Libioulle
2023-03-21 19:54:20 +01:00
committed by Xavier Bol (xbo)
parent a06a58e08b
commit ecc58cb482
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -2653,7 +2653,7 @@ class ProjectTags(models.Model):
@api.model
def _name_search(self, name, domain=None, operator='ilike', limit=None, order=None, name_get_uid=None):
if 'project_id' in self.env.context and operator == 'ilike':
if self.env.context.get('project_id') and operator == 'ilike':
# `domain` has the form of the default filter ['!', ['id', 'in', <ids>]]
# passed to exclude already selected tags -> exclude them in our query too
excluded_ids = list(domain[1][2]) \
@@ -438,3 +438,11 @@ class TestProjectFlow(TestProjectCommon, MailCommon):
self.assertEqual(len(project_A.message_ids), init_nb_log + 2,
"should have 2 new messages: one for tracking, one for template")
def test_private_task_search_tag(self):
task = self.env['project.task'].create({
'name': 'Test Private Task',
})
# Tag name_search should not raise Error if project_id is False
task.tag_ids.with_context(project_id=task.project_id.id).name_search(
args=["!", ["id", "in", []]])