'override the _render function of listView does't work in odoo

Here is my code. I want to change some fields background color according to the result of a rpc call. But the change only happens when I switch the mode between edit and save.It should be changed when I open this record.

Any idea?

var render = listRender.extend({
        init: function () {
            this._super.apply(this, arguments)
        },
        async _render() {
            const result = this._super.apply(this, arguments);
            var fields = [];
            for (let index in this.arch.children) {
                if (this.arch.children[index].tag === "field") {
                    fields.push({"field_name": this.arch.children[index].attrs.name, "index": index});
                }
            }
            var self = this;
            this.arch.children[36]["attrs"]["class"] = "red_color";
            var infos = await this._rpc({
                model: "purchase.order",
                method: "is_updated",
                args: [{"fields": fields, "id": this.state.res_ids}]
            });
            infos.data.forEach(ele => {
                this.arch.children[parseInt(ele["index"])]["attrs"]["class"] = "red_color";
            })
        },
    });

color doesn't change when I open the record

color changes when I go to the edit mode



Solution 1:[1]

Render overriding is not the right way to deal with your problem. Consider changing the corresponding view : "sale.order.form" instead. You can find it this way : in App Settings, switch to debug mode by adding "?debug=1" in your url, reload the page, then go to the new Technical Menu-tab > View.

enter image description here

and then, search for : sale.order.form

...which corresponds to the following xml files in src/odoo/addons : sale/sale_views.xml or sale_purchase/sale_views.xml and/or website_sale/sale_order_views.xml

The corresponding url must be similar too (but with different id=...):

https://yourodoodomain.com/web#id=949&action=28&model=ir.ui.view&view_type=form&cids=1&menu_id=4

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1