1
votes

I want to apply a odoo domain if the a field is not False.

['|',('versions_ids', '=', version_id),(False, '=', version_id)]

The domain like I wrote throw this error

TypeError: unhashable type: 'list'

EDIT:

The object extend:

class sale_order_line(models.Model):
    _inherit = 'sale.order.line'

    version_id = fields.Many2one('product_cars_application.version',string='Version')

the view extend

<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>
2
If you would not mind providing more context. Show the code where your domain is defined (not just the domain). Show the field definition which calls your function. - Phillip Stack
@Phillip Stack edit adding context - Mariano DAngelo
I have seen something like this. version_ids is a list, version_id is an int or False. The list int comparison is probably an issue. Wrap version_id in a list `('versions_ids', '=', [version_id]) - Phillip Stack
also use in instead of = - Phillip Stack
the first part of the domain works ok. ('versions_ids', '=', version_id). but if I only use this if version_id is False, it only shows the products with versions_ids = False, and I want to show all - Mariano DAngelo

2 Answers

0
votes

Try the following.

<xpath expr="/form/sheet/notebook/page[1]/field[@name='order_line']/tree/field[@name='product_id']" position="attributes">
    <attribute name = "domain">['|',('version_ids', '=', version_id),('version_ids','=',False),'|',('version_id','=',False)]</attribute>
</xpath>
0
votes

This should be like this,

<xpath expr="/form/sheet/notebook/page[1]/field[@name='order_line']/tree/field[@name='product_id']" position="attributes">
    <attribute name = "domain">['|',('version_ids', '=', version_id),('version_ids','=',False)]</attribute>
</xpath>

Another option for domain.

['|',('version_ids', '=', version_id),('version_ids','=',[(6,False,[])])]