这是我第一次使用 Qweb for Odoo XML。我猜由于缺乏经验,我的代码无法按预期工作。提前非常感谢您。
我有一个选择字段:
priority = fields.Selection([('critical', 'Critical'), ('urgent', 'Urgent'), ('low', 'Low')], tracking=True, help="You can give your tas a priority")
所以每个选择在我的表单视图中都有不同的颜色:
<field name="priority" decoration-danger="priority =='critical'" decoration-success="priority =='low'" decoration-warning="priority=='urgent'" class="o_project_name oe_inline"/>
我想在我的看板视图中显示彩色优先级,但它没有按预期工作:
<record id="todo_kanban" model="ir.ui.view">
<field name="name">todo.kanban</field>
<field name="model">todo</field>
<field name="arch" type="xml">
<kanban default_group_by ="stage_id" class="o_kanban_small_column o_kanban_project_tasks" on_create="quick_create" >
<field name="todo_id"/>
<field name="user_id"/>
<field name="priority"/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_details">
<strong class="o_kanban_record_title"><field name="todo_id"/></strong>
<div class="o_kanban_tags_section"/>
<ul>
<li>User : <field name="user_id"/></li>
<li>Priority : <field name="priority"/>
<t t-if="priority == 'critial'">
<t t-set="style" t-value="'color:red'" />
</t>
<t t-if="priority == 'urgent'">
<t t-set="style" t-value="'color:orange'" />
</t>
<t t-if="priority == 'low'">
<t t-set="style" t-value="'color:green'" />
</t>
</li>
</ul>
</div>
</t>
</templates>
</kanban>
</field>
</record>
我不确定您是否已经找到解决方案,但您可以尝试以下方法:
<t t-if="priority == 'critial'" t-attf-style="color:red">
</t>