'Change many2many field tags color odoo
Solution 1:[1]
You can use the color_field
option to specify the field to be used as the color index, Odoo will check if there is a color field on the related model.
If you want to define a many2many field in your custom model ('custom.model'
) for which you defined the target model to 'custom.model.tags'
and want to use the many2many_tags widget with color_field
option, you will need to define an integer field in the target model ('custom.model.tags'
).
Example:
class CustomModel(models.Model):
_name = 'custom.model'
tag_ids = fields.Many2many('custom.model.tags')
class CustomModelTags(models.Model):
_name = 'custom.model.tags'
color = fields.Integer()
Define the many2many field like following:
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
Edit:
To set the color of the tag, Odoo will prepare the render context (get the color field name and record value) and call the qweb render method using that render context and in the FieldMany2ManyTag template, it will simply add a class o_tag_color_#{color} to the tag
where color
is the value of the color field.
Odoo gets the value of the color field from the record data for each tag, so there is no option to pass the value in options or context.
Solution 2:[2]
You seem to be using many2many_tags. In this case you could use 'color_field'
<field name="field_ids"
widget="many2many_tags"
options="{'color_field': 'color'}"/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Plaoo |