首页 > 解决方案 > 如何根据one2many树中Odoo 11中的某些条件为特定字段(仅某些列)赋予颜色?

问题描述

我想在 one2many 表单视图中为特定字段值提供颜色。这是我的示例代码。

 <field name="custom_order_line" mode="tree,kanban" attrs="{'readonly': [('state', '=', 'validate')]}">
    <tree colors="red:customs_sale_price &lt; price_unit;green:customs_sale_price &gt; price_unit;" string="Customs Order Lines" editable="bottom">
        <field name="customs_sale_price" colors="green:state == 'draft' "/>
        <field name="customs_cost_price" colors="red:customs_cost_price &lt; customs_sale_price"/>
    </tree>
</field>

标签: xmlodooodoo-11odoo-view

解决方案


我找到了一个模块 ( web_tree_dynamic_colored_field) 可以满足您的需要。检查链接

改变bg_color颜色的例子:

<field name="arch" type="xml">
    <tree string="View name">
        ...
        <field name="name" options='{"bg_color": "red: customer == True"}'/>
        ...
    </tree>
</field>

改变fg_color颜色的例子:

<field name="arch" type="xml">
    <tree string="View name">
        ...
        <field name="name" options='{"fg_color": "white:customer == True"}'/>
        ...
    </tree>
</field>

注意:您应该始终对字段使用单引号options并将嵌套值用双引号括起来,因为options它是一个 JSON 对象。

装饰器

如果您只想为行着色,可以使用装饰器(仅适用于 11 版本)

decoration-bf - shows the line in BOLD 
decoration-it - shows the line in ITALICS 
decoration-danger - shows the line in LIGHT RED 
decoration-info - shows the line in LIGHT BLUE 
decoration-muted - shows the line in LIGHT GRAY 
decoration-primary - shows the line in LIGHT PURPLE 
decoration-success - shows the line in LIGHT GREEN 
decoration-warning - shows the line in LIGHT BROWN

句法

<tree decoration-type="field=='value'">

例子

<tree decoration-success="state=='done'">

推荐阅读