can anyone help me get my case to run? I want to color the line of a many2one treeview by the value of a field inside the line.
<field colspan="2" name="timesheet_ids" class="custom-field" widget="one2many"
nolabel="1">
<tree editable="bottom" >
<field name="sequence" colors="red:is_line_nonsense == True"/>
<field name="time_event_type"/>
<field name="date" attrs="{'readonly': [('is_date_readonly', '=', True)]}"/>
<field name="is_begin_readonly" invisible="1"/>
<field name="is_end_readonly" invisible="1"/>
<field name="is_date_readonly" invisible="1"/>
<field name="is_line_nonsense" invisible="1"/>
<field name="begin_time"
attrs="{'readonly': [('is_begin_readonly', '=', True)]}"
widget="float_time"/>
<field name="end_time" attrs="{'readonly': [('is_end_readonly', '=', True)]}"
widget="float_time"/>
<field name="total_hours" widget="float_time" readonly="true"/>
</tree>
</field>
I want that the line bg gets red when the field is_line_nonsense = true.
Here is the JS code.
odoo.define('chn_events.highlight_rows', function (require) {
"use strict";
var ListRenderer = require('web.ListRenderer');
ListRenderer.include({
_renderRow: function (record, index) {
var $row = this._super.apply(this, arguments);
var color = record.data.color;
if (color) {
$row.css('background-color', color);
}
return $row;
},
});
});
but it doesn't work, the script is loaded but no color will be shown.
I also tried with a module. https://odoo-community.org/shop/colorize-field-in-tree-views-2814#attr=21700 That also didn't work but I think it's because the module is for version 15 and I have 16.
Does anyone have an idea for the solution?
Have you properly added the path to your js-file in the
assets
entry of your__manifest__.py
file ?Where does your
record.data.color
come from ?using
$tr.addClass('your_class_color_red')
, that needs to be defined in css :.your_class_color_red{ background-color: red !important;}
... would match better the original code than yourrecord.data.color
The original js file : /addons/web/static/src/legacy/js/views/list/list_renderer.js
An example of inheritance existing as standard in v16 (/addons/web/static/src/legacy/js/views/list/list_editable_renderer.js):