TreeView中使用颜色装饰器(decoration-${NAME})时对于Many2one字段的一个小坑

admin 2020-9-17 13398



今天想要对列表(TreeView)使用颜色装饰器装饰一下,不同状态的记录用不同颜色区分。多数人是这么写:

    <tree 
      string="Manufacturing Orders"
      default_order="date_planned_start desc" 
      decoration-bf="message_needaction==True" 
      decoration-info="state=='confirmed'" 
      decoration-danger="date_planned_start &lt; current_date and state not in ('done','cancel')" 
      decoration-muted="state in ('done','cancel')" 
      >

这样写对于简单字段没问题。按惯性思维,对于many2one字段,应该是这样(比如many2one字段为 location,其中有id和name):

    <tree string="包裹列表"
        decoration-info="location.name=='进境港'"
        decoration-bf="location.name in ('收货区', '理货区', '存储区', '收货区', '收货区') "
        decoration-primary="location.name=='上线区'"
        decoration-warning="location.name=='查验区'"
        decoration-success="location.name in ('出库区', '放行区', '提货区') "
        decoration-muted="location.name=='客户区'"
        decoration-danger="location.name in ('暂扣区', '罚没区', '销毁区', '退运区') "
    >

可以一运行就会报错说Object没有name属性。跟踪代码运行发现:在js中,many2one字段是以数组方式存储的,改成下面的方式就可以了:

    <tree string="包裹列表"
        decoration-info="location[1]=='进境港'"
        decoration-bf="location[1] in ('收货区', '理货区', '存储区', '收货区', '收货区') "
        decoration-primary="location[1]=='上线区'"
        decoration-warning="location[1]=='查验区'"
        decoration-success="location[1] in ('出库区', '放行区', '提货区') "
        decoration-muted="location[1]=='客户区'"
        decoration-danger="location[1] in ('暂扣区', '罚没区', '销毁区', '退运区') "
    >


最新回复 (0)
返回