From 85b199b9be57a9d175ef44bc85476a62cc437e16 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 22 Apr 2020 11:31:02 +0000 Subject: [PATCH] [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) --- addons/hr/models/hr_employee_category.py | 7 ++++++- addons/hr_recruitment/models/hr_recruitment.py | 7 ++++++- addons/project/models/project.py | 6 +++++- addons/repair/models/repair.py | 6 +++++- addons/sales_team/models/crm_tag.py | 8 ++++++-- addons/website_event_track/models/event_track.py | 9 ++++++++- odoo/addons/base/models/res_partner.py | 6 +++++- 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/addons/hr/models/hr_employee_category.py b/addons/hr/models/hr_employee_category.py index dbd14f81a94..41f8bedfbe4 100644 --- a/addons/hr/models/hr_employee_category.py +++ b/addons/hr/models/hr_employee_category.py @@ -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 = [ diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index e18d4564948..a17e1a5e957 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -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 !"), diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 2e73c760ab4..4da8ee5c2d0 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -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!"), diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index f26ef87900a..ed642164b07 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -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!"), diff --git a/addons/sales_team/models/crm_tag.py b/addons/sales_team/models/crm_tag.py index a0db292a292..205a7ada165 100644 --- a/addons/sales_team/models/crm_tag.py +++ b/addons/sales_team/models/crm_tag.py @@ -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 !"), diff --git a/addons/website_event_track/models/event_track.py b/addons/website_event_track/models/event_track.py index 205b8e4e969..31054d09855 100644 --- a/addons/website_event_track/models/event_track.py +++ b/addons/website_event_track/models/event_track.py @@ -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 !"), diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py index 14e8c634339..63048f138ff 100644 --- a/odoo/addons/base/models/res_partner.py +++ b/odoo/addons/base/models/res_partner.py @@ -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.")