Skip to content

Commit

Permalink
[MIG] web_tree_dynamic_colored_field: Migration to 13.0
Browse files Browse the repository at this point in the history
Use 'options' instead of 'colors' on tree views

The colors attribute has been removed from the RelaxNG schema in
Odoo [0], so use the 'options' instead.

Closes OCA#1479

[0] odoo/odoo@7024f8d#diff-e9acd2f731cc01f302055b6e232df983
  • Loading branch information
guewen authored and Herqs committed Apr 4, 2022
1 parent 5093be0 commit ccade0f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion web_tree_dynamic_colored_field/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Colorize field in tree views",
"summary": "Allows you to dynamically color fields on tree views",
"category": "Hidden/Dependency",
"version": "12.0.1.0.0",
"version": "13.0.1.0.0",
"depends": ["web"],
"author": "Camptocamp, Therp BV, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
2 changes: 1 addition & 1 deletion web_tree_dynamic_colored_field/demo/res_users.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="inherit_id" ref="base.view_users_tree" />
<field name="arch" type="xml">
<tree position="attributes">
<attribute name="colors">color_field: lang</attribute>
<attribute name="options">{"color_field": "lang"}</attribute>
</tree>
<field name="login_date" position="attributes">
<attribute name="options">{
Expand Down
6 changes: 3 additions & 3 deletions web_tree_dynamic_colored_field/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
This module aims to add support for dynamically coloring fields in tree view
according to data in the record.

It provides attributes on fields with the similar syntax as the ``colors`` attribute
It provides attributes on fields with a similar syntax as the ``colors`` attribute
in tree tags.

Further, it provides a ``color_field`` attribute on tree tags's ``colors`` to use
Further, it provides a ``color_field`` attribute on tree tags's ``options`` to use
a field's value as color.

Features
========

* Add attribute ``bg_color`` on field's ``options`` to color background of a cell in tree view
* Add attribute ``fg_color`` on field's ``options`` to change text color of a cell in tree view
* Add attribute ``color_field`` on the tree element's ``colors`` to use as color
* Add attribute ``color_field`` on the tree element's ``options`` to use as color
4 changes: 2 additions & 2 deletions web_tree_dynamic_colored_field/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

With this example, column which renders 'name' field will have its text colored in white on a customer records.

* In the tree view declaration, use ``options='"color_field": "my_color"'`` attribute in the ``tree`` tag::
* In the tree view declaration, use ``options='{"color_field": "my_color"}'`` attribute in the ``tree`` tag::

...
<field name="arch" type="xml">
<tree string="View name" colors="color_field: my_color" >
<tree string="View name" options='{"color_field": "my_color"}' >
...
<field name="my_color" invisible="1"/>
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
* @override
*/
_renderBody: function () {
if (this.arch.attrs.colors) {
var colorAttr = this.arch.attrs.colors.split(';');
if (colorAttr.length > 0) {
var colorField = colorAttr[0].split(':')[1].trim();
// validate the presence of that field in tree view
if (this.arch.attrs.options) {
var archOptions = this.arch.attrs.options;
if (!_.isObject(archOptions)) {
archOptions = pyUtils.py_eval(archOptions);
}
var colorField = archOptions.color_field;
if (colorField) {
// Validate the presence of that field in tree view
if (this.state.data.length && colorField in this.state.data[0].data) {
this.colorField = colorField;
} else {
Expand Down

0 comments on commit ccade0f

Please sign in to comment.