[IMP] various: Set a default random color on certain tags

Purpose
=======

For a tag to be displayed on a kanban card, it needs to have a color set.
We won't be changing that behaviour, since it would mean having
two options > the color, and whether or not to show it in the kanban

The purpose of this task is to set a color on new tags to make the user
save a bit more time, set a color for him as he might not find the feature,
and make sure the tag will be on the kanban cards.

Specification
=============

For each of the following models, at creation, set a random integer between
1 and 11 in field 'color'

Models:
res.partner.category
crm.tag
project.tags
hr.applicant.category
helpdesk.tag
hr.employee.category
event.track.tag
mrp.eco.tag
repair.tags

closes odoo/odoo#49967

Taskid: 2234527
Related: odoo/enterprise#10112
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Yannick Tivisse
2020-04-22 11:32:35 +00:00
parent 45170ceeb5
commit 85b199b9be
7 changed files with 41 additions and 8 deletions
+6 -1
View File
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from random import randint
from odoo import fields, models
@@ -9,8 +11,11 @@ class EmployeeCategory(models.Model):
_name = "hr.employee.category"
_description = "Employee Category"
def _get_default_color(self):
return randint(1, 11)
name = fields.Char(string="Tag Name", required=True)
color = fields.Integer(string='Color Index')
color = fields.Integer(string='Color Index', default=_get_default_color)
employee_ids = fields.Many2many('hr.employee', 'employee_category_rel', 'category_id', 'emp_id', string='Employees')
_sql_constraints = [
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from random import randint
from odoo import api, fields, models, tools, SUPERUSER_ID
from odoo.tools.translate import _
from odoo.exceptions import UserError
@@ -518,8 +520,11 @@ class ApplicantCategory(models.Model):
_name = "hr.applicant.category"
_description = "Category of applicant"
def _get_default_color(self):
return randint(1, 11)
name = fields.Char("Tag Name", required=True)
color = fields.Integer(string='Color Index', default=10)
color = fields.Integer(string='Color Index', default=_get_default_color)
_sql_constraints = [
('name_uniq', 'unique (name)', "Tag name already exists !"),
+5 -1
View File
@@ -3,6 +3,7 @@
import ast
from datetime import timedelta
from random import randint
from odoo import api, fields, models, tools, SUPERUSER_ID, _
from odoo.exceptions import UserError, AccessError, ValidationError, RedirectWarning
@@ -1074,8 +1075,11 @@ class ProjectTags(models.Model):
_name = "project.tags"
_description = "Project Tags"
def _get_default_color(self):
return randint(1, 11)
name = fields.Char('Tag Name', required=True)
color = fields.Integer(string='Color Index')
color = fields.Integer(string='Color Index', default=_get_default_color)
_sql_constraints = [
('name_uniq', 'unique (name)', "Tag name already exists!"),
+5 -1
View File
@@ -1,6 +1,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from collections import defaultdict
from random import randint
from odoo import api, fields, models, _
from odoo.exceptions import UserError, ValidationError
@@ -794,8 +795,11 @@ class RepairTags(models.Model):
_name = "repair.tags"
_description = "Repair Tags"
def _get_default_color(self):
return randint(1, 11)
name = fields.Char('Tag Name', required=True)
color = fields.Integer(string='Color Index')
color = fields.Integer(string='Color Index', default=_get_default_color)
_sql_constraints = [
('name_uniq', 'unique (name)', "Tag name already exists!"),
+6 -2
View File
@@ -1,16 +1,20 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from random import randint
from odoo import fields, models
class Tag(models.Model):
_name = "crm.tag"
_description = "CRM Tag"
def _get_default_color(self):
return randint(1, 11)
name = fields.Char('Tag Name', required=True, translate=True)
color = fields.Integer('Color Index')
color = fields.Integer('Color Index', default=_get_default_color)
_sql_constraints = [
('name_uniq', 'unique (name)', "Tag name already exists !"),
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from random import randint
from odoo import api, fields, models
from odoo.tools.translate import _, html_translate
from odoo.addons.http_routing.models.ir_http import slug
@@ -12,9 +14,14 @@ class TrackTag(models.Model):
_description = 'Event Track Tag'
_order = 'name'
def _get_default_color(self):
return randint(1, 11)
name = fields.Char('Tag Name', required=True)
track_ids = fields.Many2many('event.track', string='Tracks')
color = fields.Integer(string='Color Index', help="Note that colorless tags won't be available on the website.")
color = fields.Integer(
string='Color Index', default=_get_default_color,
help="Note that colorless tags won't be available on the website.")
_sql_constraints = [
('name_uniq', 'unique (name)', "Tag name already exists !"),
+5 -1
View File
@@ -11,6 +11,7 @@ import re
import requests
from lxml import etree
from random import randint
from werkzeug import urls
from odoo import api, fields, models, tools, _
@@ -72,8 +73,11 @@ class PartnerCategory(models.Model):
_order = 'name'
_parent_store = True
def _get_default_color(self):
return randint(1, 11)
name = fields.Char(string='Tag Name', required=True, translate=True)
color = fields.Integer(string='Color Index')
color = fields.Integer(string='Color Index', default=_get_default_color)
parent_id = fields.Many2one('res.partner.category', string='Parent Category', index=True, ondelete='cascade')
child_ids = fields.One2many('res.partner.category', 'parent_id', string='Child Tags')
active = fields.Boolean(default=True, help="The active field allows you to hide the category without removing it.")