Browse Source

web_tree_dynamic_colored_field: Assume that color may not start with 'color_field'

The index at 0 in the following code:
  var colorField = this.arch.attrs.colors.split(';')
  .filter(color => color.trim().startsWith('color_field'))[0]
Was failing on such valid xml:
  <tree string="Buffer monitor"
        colors="red:procure_recommended_qty &gt; 0">
pull/1223/head
Guewen Baconnier 6 years ago
committed by mreficent
parent
commit
71fd048442
  1. 27
      web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

27
web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

@ -12,20 +12,21 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
*/
_renderBody: function () {
if (this.arch.attrs.colors) {
var colorField = this.arch.attrs.colors.split(';')
.filter(color => color.trim().startsWith('color_field'))[0]
.split(':')[1]
.trim();
// validate the presence of that field in tree view
var fieldNames = _(this.columns).map(
(value) => { return value.attrs.name; }
);
if (fieldNames.indexOf(colorField) === -1) {
console.warn(
"No field named '" + colorField + "' present in view."
var colorAttr = this.arch.attrs.colors.split(';')
.filter(color => color.trim().startsWith('color_field'));
if (colorAttr.length > 0) {
var colorField = colorAttr[0].split(':')[1].trim();
// validate the presence of that field in tree view
var fieldNames = _(this.columns).map(
(value) => { return value.attrs.name; }
);
} else {
this.colorField = colorField;
if (fieldNames.indexOf(colorField) === -1) {
console.warn(
"No field named '" + colorField + "' present in view."
);
} else {
this.colorField = colorField;
}
}
}
return this._super();

Loading…
Cancel
Save