打开ERP。在树视图中动态地将图像添加到字段中

OpenERP. Add image into field dynamically in a tree view

我正在使用 v7 并且我想在 tree view 中根据同一行中的其他字段值显示带有图像图标(如信号量)的字段.

实际上,我通过函数字段获得了我想要的功能,并将结果作为字符串,但我真的希望它作为图像。我不知道是否可以从函数 return HTML 所以我决定用 jQuery.

我使用浏览器控制台实现了 jQuery 代码并且可以工作,但是当我将 jQuery code 放在视图中时,"data-field" 选择器没有被选中。

拜托,任何人都可以向我解释原因或告诉我另一种获取我的 objective 的方法吗?

列表

列表视图的根元素是。列表视图的根可以具有以下属性:

可编辑,default_order,颜色,字体,创建,编辑,删除,on_write,字符串

查看更多关于

您可以通过在列表视图中定义子元素 button 来实现这一点。 我在产品中添加了图标,以根据产品状态显示产品是否可用/保留/已售出。

  • 按钮

    图标:用于显示按钮的图标

Xml 在列表视图中显示图标的代码。

<xpath expr="//notebook/page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='product_id']" position="before">
      <field name="product_status" invisible="1" />
      <button icon='Hold' readonly="1" attrs="{'invisible':[('product_status', '!=', 'hold')]}"/>
      <button icon='Available' readonly="1" attrs="{'invisible':[('product_status', '!=', 'available')]}"/>
      <button icon='sold' readonly="1" attrs="{'invisible':[('product_status', '!=', 'sold')]}"/>
</xpath>

注意

  • 记住您定义按钮可见性的基础字段必须是 出现在列表视图上,不管它是否可见,但它 必须存在,如上例中的 product_status
  • 基本字段必须是 store=True.

    为什么 store=True ?

Reason: when you set any function field store=True then it will physically created in database, while you give this field name in domain the odoo framework add this field directly in WHERE clause, it will not access through browsable object, so if your field is store=False then it won't be able to find that field and gives you an error.

  • 图标必须出现在 web/static/src/img/icons.
  • 如果你想在你的自定义模块中保留图标,那么你必须在你的模块文件夹中为它创建相同的层次结构创建 /static/src/img/icons 并保留所有那里有图标。

xpath 用于定义您想要 add/update 字段的位置。

查看更多关于 xpath