当我在odoo11中的kanban视图中添加一个图像字段时,它提出了一个错误:"QWeb2 - template'kanban-box':运行时错误: TypeError:无法读取未定义的属性'raw_value‘“。在odoo 9中,同样的代码也适用于我。我很惊讶地发现了问题的原因。下面是我的代码。
Python代码
class Test(models.Model):
_name = "test.test"
image = fields.Binary(attachment=True) XML代码
<record id = "test_id" model = "ir.ui.view">
<field name = "name">Test Image</field>
<field name = "model">test.test</field>
<field name = "arch" type = "xml">
<kanban>
<field name="image" />
<templates>
<t t-name="kanban-box">
<div class="oe_resource_vignette">
<div class="oe_resource_image">
<img t-att-src="kanban_image('test.test','image',record.id.raw_value)" class="oe_resource_picture"/>
</div>
</templates>
</kanban>
</field>
</record>谢谢你的支持和时间。
发布于 2021-10-12 19:41:47
如果要引用id字段,则需要将其添加到kanban视图(在任何视图中)。这也适用于Odoo 14。
在下面的代码中添加了<field name="id" attrs="{'invisible': True}"/>:
<record id = "test_id" model = "ir.ui.view">
<field name = "name">Test Image</field>
<field name = "model">test.test</field>
<field name = "arch" type = "xml">
<kanban>
<field name="image" />
<templates>
<t t-name="kanban-box">
<div class="oe_resource_vignette">
<div class="oe_resource_image">
<img t-att-src="kanban_image('test.test','image',record.id.raw_value)" class="oe_resource_picture"/>
</div>
</templates>
<field name="id" attrs="{'invisible': True}"/>
</kanban>
</field>
</record>看板文档:https://www.odoo.com/documentation/11.0/howtos/backend.html#kanban
发布于 2018-03-30 07:18:24
可以通过添加"id“来尝试它。
<record id = "test_id" model = "ir.ui.view">
<field name = "name">Test Image</field>
<field name = "model">test.test</field>
<field name = "arch" type = "xml">
<kanban>
<field name="id"/>
<field name="image"/>
<templates>
<t t-name="kanban-box">
<div class="oe_resource_vignette">
<div class="oe_resource_image">
<img t-att-src="kanban_image('test.test','image',record.id.raw_value)" class="oe_resource_picture"/>
</div>
</templates>
</kanban>
</field>
https://stackoverflow.com/questions/48594204
复制相似问题