odoo xml的错误解决过程 Uncaught TypeError: b.__contains__ is not a function

在 xml 中,加入 decoration-bf 属性错误的解决

问题描述:

odoo xml的错误解决过程  Uncaught TypeError: b.__contains__ is not a function

打算测试 decoration-属性

修改视图:

 

<record id="view_all_customers_list" model="ir.ui.view">
        <field name="name">all partner list</field>
        <field name="model">res.partner</field>
        <field name="priority">1</field>
        <field name="arch" type="xml" >
            <tree decoration-danger="('11111' in name) or ('(870)' in phone) "
           >
                <field name="name"/>
                <field name="phone"/>
                <field name="email"/>
            </tree>
        </field>

    </record>

一直出现错误:

Uncaught TypeError: b.__contains__ is not a function

只保留('11111' in name)  则正确。一旦 增加  ('(870)' in phone) 则错误。。

查看odoo 的 官方文档. decoration-属性。。

decoration-{$name}

allow changing the style of a row’s text based on the corresponding record’s attributes.

Values are Python expressions. For each record, the expression is evaluated with the record’s attributes as context values and if true, the corresponding style is applied to the row. Other context values are uid (the id of the current user) and current_date (the current date as a string of the form yyyy-MM-dd).

可以看出 里面就是 python表达式,但是为什么一直不对

只能调试js 查看了

定位到错误地方

   var evaluate_operator = function (operator, a, b) {
        switch (operator) {
        case 'is': return a === b ? py.True : py.False;
        case 'is not': return a !== b ? py.True : py.False;
        case 'in':
		#这里就看到了b不允许为空的,但这里没有做判断
            return b.__contains__(a);
        case 'not in':
            return py.PY_isTrue(b.__contains__(a)) ? py.False : py.True;
        case '==': case '!=': case '<>':
        case '<': case '<=':
        case '>': case '>=':
            return PY_op(a, b, operator);
        }
        throw new Error('SyntaxError: unknown comparator [[' + operator + ']]');
    };

找到 错误原因,因为 phone 可以为空,所以这里错误了。。。

 

修改错误

<tree decoration-danger="('11111' in name) or (phone and ('870' in phone)) "
>

odoo xml的错误解决过程  Uncaught TypeError: b.__contains__ is not a function

上一篇:(node:11224) UnhandledPromiseRejectionWarning: TypeError: this.getResolve is not a function


下一篇:TypeError: Order() got an unexpected keyword argument 'xxx'