我想在one2many表单视图中为特定字段值指定颜色。这是我的示例代码。
<field name="custom_order_line" mode="tree,kanban" attrs="{'readonly': [('state', '=', 'validate')]}">
<tree colors="red:customs_sale_price < price_unit;green:customs_sale_price > 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 < customs_sale_price"/>
</tree>
</field>
答案 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
使用单引号并将嵌套值括在双引号中。
如果您只想为行着色,则可以使用装饰器(仅适用于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'">