【发布时间】:2016-11-15 21:02:21
【问题描述】:
如果 a 字段不为 False,我想申请一个 odoo 域。
['|',('versions_ids', '=', version_id),(False, '=', version_id)]
像我写的域抛出这个错误
TypeError: unhashable type: 'list'
编辑:
对象扩展:
class sale_order_line(models.Model):
_inherit = 'sale.order.line'
version_id = fields.Many2one('product_cars_application.version',string='Version')
视图扩展
<record id="sale_cars_append" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="." position="inside">
<script type='text/javascript' src='/product_cars_application/static/src/js/filter.js'></script>
</xpath>
<xpath expr="/form/sheet/notebook/page[1]/field[@name='order_line']/tree/field[@name='product_id']" position="before">
<!-- <button name="product_search" type="action" class="oe_highlight" icon="fa-car" /> -->
<field name="version_id"/>
</xpath>
<xpath expr="/form/sheet/notebook/page[1]/field[@name='order_line']/tree/field[@name='product_id']" position="attributes">
<attribute name = "domain">['|',('versions_ids', '=', version_id),(False, '=', version_id)]</attribute>
</xpath>
</field>
</record>
【问题讨论】:
-
如果您不介意提供更多上下文。显示定义域的代码(不仅仅是域)。显示调用你的函数的字段定义。
-
@Phillip Stack 编辑添加上下文
-
我见过这样的事情。 version_ids 是一个列表,version_id 是一个 int 或 False。 list int 比较可能是一个问题。将
version_id包裹在列表 `('versions_ids', '=', [version_id]) -
也使用
in而不是= -
域的第一部分工作正常。 ('versions_ids'、'='、version_id)。但是如果我只在version_id为False的情况下使用它,它只显示versions_ids = False的产品,我想显示所有