如何根据Odoo 11中的条件在one2many树中为特定字段(仅某些列)赋予颜色?

时间:2018-07-06 12:59:56

标签: xml odoo odoo-11 odoo-view

我想在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>

1 个答案:

答案 0 :(得分:1)

我找到了满足您需求的模块(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是JSON对象,因此您应始终对字段options使用单引号并将嵌套值括在双引号中。

Decorators

如果您只想为行着色,则可以使用装饰器(仅适用于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'">