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

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

问题描述:

打算测试 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)) "
>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值