xml - 如何根据one2many树中Odoo 11中的某些条件为特定字段(仅某些列)赋予颜色?
问题描述
我想在 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>
解决方案
我找到了一个模块 ( 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'">
推荐阅读
- typescript - Joi 验证自引用嵌套模式
- excel - 使用“格式为表格”过滤行很慢
- mysql - 在 AWS EC2 中连接 MySQL 数据库
- node.js - 为什么我的承诺链是同时运行的,而不是顺序运行的
- perl - Perl 如果带有“+”、“-”、“*”、“/”
- python - Django 从多个函数创建类
- firebase - 如何在firebase中实现这个.htaccess?
- flutter - 当我们并行运行测试时,使用全局顶级变量有什么副作用吗?
- python - NoReverseMatch at ...... in django
- php - localhost 将您重定向了太多次。拉拉维尔