[IMP] project: improve tags management

In big databases, the number of tags becomes rapidly huge. This makes
it very hard to find revelant tags. In practice, the same few tags are
usually used in a given project.

This commit:
- Limits the search of tags to the project's tags of the task as well
  as to the tasks' tags of the task's project.
- Prevents creating case sensitive variants of existing tags.
- Reuse existing tags from other projects and other projects' tasks
  when the user `creates` (or at least thinks creating as the
  _name_search would not return the searched tag) a new tag in his project.

task-2735833

closes odoo/odoo#82925

Related: odoo/enterprise#23814
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
This commit is contained in:
Cedric Prieels
2022-02-12 19:26:16 +00:00
committed by Laurent Stukkens (LTU)
parent 10a5796d4b
commit 7e35518129
2 changed files with 23 additions and 3 deletions
+21 -1
View File
@@ -11,7 +11,7 @@ from random import randint
from odoo import api, Command, fields, models, tools, SUPERUSER_ID, _
from odoo.exceptions import UserError, ValidationError, AccessError
from odoo.tools import format_amount
from odoo.osv.expression import OR
from odoo.osv.expression import OR, AND
from odoo.tools.misc import get_lang
from .project_task_recurrence import DAYS, WEEKS
@@ -2233,7 +2233,27 @@ class ProjectTags(models.Model):
name = fields.Char('Name', required=True, translate=True)
color = fields.Integer(string='Color', default=_get_default_color)
project_ids = fields.Many2many('project.project', 'project_project_project_tags_rel', string='Projects')
task_ids = fields.Many2many('project.task', string='Tasks')
_sql_constraints = [
('name_uniq', 'unique (name)', "Tag name already exists!"),
]
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
domain = args
if 'project_id' in self.env.context:
project_id = self.env.context.get('project_id')
domain = AND([
domain,
['|', ('task_ids.project_id', '=', project_id), ('project_ids', 'in', project_id)]
])
return super()._name_search(name, domain, operator, limit, name_get_uid)
@api.model
def name_create(self, name):
existing_tag = self.search([('name', '=ilike', name.strip())], limit=1)
if existing_tag:
return existing_tag.name_get()[0]
return super().name_create(name)
+2 -2
View File
@@ -923,7 +923,7 @@
<field name="partner_id" widget="res_partner_many2one" class="o_task_customer_field"/>
<field name="partner_phone" widget="phone" attrs="{'invisible': True}"/>
<field name="date_deadline" attrs="{'invisible': [('is_closed', '=', True)]}"/>
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}"/>
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}" context="{'project_id': project_id}"/>
<field name="recurring_task" attrs="{'invisible': [('allow_recurring_tasks', '=', False)]}" />
<field name="legend_blocked" invisible="1"/>
<field name="legend_normal" invisible="1"/>
@@ -1210,7 +1210,7 @@
<field name="company_id" groups="base.group_multi_company" optional="show"/>
<field name="activity_ids" widget="list_activity" optional="show"/>
<field name="date_deadline" optional="hide" widget="remaining_days" attrs="{'invisible': [('is_closed', '=', True)]}"/>
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" optional="show"/>
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" optional="show" context="{'project_id': project_id}"/>
<field name="rating_last_text" string="Rating" decoration-danger="rating_last_text == 'ko'"
decoration-warning="rating_last_text == 'ok'" decoration-success="rating_last_text == 'top'"
attrs="{'invisible': [('rating_last_text', '=', 'none')]}"