Skip to Content
Menu
This question has been flagged
1 Reply
3873 Views

Hello, everybody, how are you doing today?

I am attempting to add random colours to my custom tags, and it is working well. However, I want more colour options to select from in Odoo. Is it possible to generate random colours and allocate them to the tags in a manner that Odoo can recognise them? Below is a functioning solution using the limited colours Odoo offers (11 indexes):

---

import random
from odoo import fields, models


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real Estate Property Tag"
_sql_constraints = [
("check_unique_name", "UNIQUE(name)", "The name must be unique"),
]

name = fields.Char("Name", required=True)
color = fields.Integer(string="Color Index")

property_ids = fields.Many2many("estate.property", "property_tag_id", string="Properties")

def create(self, vals):
vals['color'] = random.randint(1, 11)

result = super(EstatePropertyTag, self).create(vals)
return result

---

Please let me know if there is any sort of solution to randomly add hexadecimal colour values to Odoo tags or to extend Odoo's colour index list. Thank you and have a great time!

Avatar
Discard
Best Answer

Hi,

You can add new colors

.o_tag.o_tag_color_{number} {
background-color: #hexcode !important;
}

Regards

Avatar
Discard
Related Posts Replies Views Activity
0
Oct 18
3545
1
Oct 23
3264
2
Dec 21
7355
1
Aug 21
2540
6
Jan 19
9157