diff --git a/web_tree_dynamic_colored_field/__manifest__.py b/web_tree_dynamic_colored_field/__manifest__.py index 13e207f11..e96b33579 100644 --- a/web_tree_dynamic_colored_field/__manifest__.py +++ b/web_tree_dynamic_colored_field/__manifest__.py @@ -6,7 +6,7 @@ 'category': 'Hidden/Dependency', 'version': '12.0.1.0.0', 'depends': ['web'], - 'author': "Camptocamp, Therp BV, Odoo Community Association (OCA)", + 'author': "Camptocamp, Therp BV, GRAP, Odoo Community Association (OCA)", 'license': 'AGPL-3', 'website': 'https://github.com/OCA/web', 'demo': [ diff --git a/web_tree_dynamic_colored_field/readme/CONTRIBUTORS.rst b/web_tree_dynamic_colored_field/readme/CONTRIBUTORS.rst index a1e31ed6c..617341685 100644 --- a/web_tree_dynamic_colored_field/readme/CONTRIBUTORS.rst +++ b/web_tree_dynamic_colored_field/readme/CONTRIBUTORS.rst @@ -2,3 +2,4 @@ * Holger Brunn * Artem Kostyuk * Guewen Baconnier +* Sylvain LE GAL diff --git a/web_tree_dynamic_colored_field/readme/USAGE.rst b/web_tree_dynamic_colored_field/readme/USAGE.rst index 921a3262c..251009474 100644 --- a/web_tree_dynamic_colored_field/readme/USAGE.rst +++ b/web_tree_dynamic_colored_field/readme/USAGE.rst @@ -38,6 +38,9 @@ ... +* You can also use ``colors="bg_color_field: my_color"`` to defined the field name that will be used + for the background color of the line. + * If you want to use more than one color, you can split the attributes using ';': .. code:: diff --git a/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js b/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js index b1aa0407c..50267976e 100644 --- a/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js +++ b/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js @@ -6,7 +6,7 @@ odoo.define('web_tree_dynamic_colored_field', function (require) { ListRenderer.include({ /** - * Look up for a `color_field` parameter in tree `colors` attribute + * Look up for a `color_field` or ``bg_color_field`` parameter in tree `colors` attribute * * @override */ @@ -14,10 +14,15 @@ odoo.define('web_tree_dynamic_colored_field', function (require) { if (this.arch.attrs.colors) { var colorAttr = this.arch.attrs.colors.split(';'); if (colorAttr.length > 0) { + var colorType = colorAttr[0].split(':')[0].trim() var colorField = colorAttr[0].split(':')[1].trim(); // validate the presence of that field in tree view if (this.state.data.length && colorField in this.state.data[0].data) { - this.colorField = colorField; + if (colorType === "color_field") { + this.colorField = colorField; + } else if (colorType === "bg_color_field") { + this.bgColorField = colorField; + } } else { console.warn( "No field named '" + colorField + "' present in view." @@ -51,6 +56,10 @@ odoo.define('web_tree_dynamic_colored_field', function (require) { if (treeColor) { $td.css('color', treeColor); } + var treeBgColor = record.data[this.bgColorField]; + if (treeBgColor) { + $td.css('background-color', treeBgColor); + } // apply 's own `options` if (!node.attrs.options) { return; } if (node.tag !== 'field') { return; }