3
0
Fork 0

[IMP] web_tree_dynamic_colored_field: black, isort, prettier

15.0-ocabot-merge-pr-2789-by-pedrobaeza-bump-patch
Adam Heinz 2022-02-11 11:58:13 -05:00
parent 9994bc636b
commit a9eb43b835
3 changed files with 23 additions and 9 deletions

View File

@ -0,0 +1 @@
../../../../web_tree_dynamic_colored_field

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@ -13,12 +13,15 @@ odoo.define("web_tree_dynamic_colored_field", function (require) {
*/ */
_renderBody: function () { _renderBody: function () {
if (this.arch.attrs.colors) { if (this.arch.attrs.colors) {
var colorAttr = this.arch.attrs.colors.split(';'); var colorAttr = this.arch.attrs.colors.split(";");
if (colorAttr.length > 0) { if (colorAttr.length > 0) {
var colorType = colorAttr[0].split(':')[0].trim() var colorType = colorAttr[0].split(":")[0].trim();
var colorField = colorAttr[0].split(':')[1].trim(); var colorField = colorAttr[0].split(":")[1].trim();
// validate the presence of that field in tree view // Validate the presence of that field in tree view
if (this.state.data.length && colorField in this.state.data[0].data) { if (
this.state.data.length &&
colorField in this.state.data[0].data
) {
if (colorType === "color_field") { if (colorType === "color_field") {
this.colorField = colorField; this.colorField = colorField;
} else if (colorType === "bg_color_field") { } else if (colorType === "bg_color_field") {
@ -62,11 +65,15 @@ odoo.define("web_tree_dynamic_colored_field", function (require) {
} }
var treeBgColor = record.data[this.bgColorField]; var treeBgColor = record.data[this.bgColorField];
if (treeBgColor) { if (treeBgColor) {
$td.css('background-color', treeBgColor); $td.css("background-color", treeBgColor);
}
// Apply <field>'s own `options`
if (!node.attrs.options) {
return;
}
if (node.tag !== "field") {
return;
} }
// apply <field>'s own `options`
if (!node.attrs.options) { return; }
if (node.tag !== 'field') { return; }
var nodeOptions = node.attrs.options; var nodeOptions = node.attrs.options;
if (!_.isObject(nodeOptions)) { if (!_.isObject(nodeOptions)) {
nodeOptions = pyUtils.py_eval(nodeOptions); nodeOptions = pyUtils.py_eval(nodeOptions);