More than one OR in Odoo ORM domains

I’ve been using Odoo for some time and written some apps for the printing industry. I’ve actually tried it since it was called TinyERP then OpenERP and now Odoo. In the last couple of years, its documentation went from abysmal to somewhat decent. It is still far from complete but at least one can have a hope of making progress at Odoo development.

There is a ton of undocumented stuff that i’ve found over the years and wanted to blog but had no time (Twitter is easy yo!).

Much of the ‘documentation is basically looking into the source code itself.

So my problem was simple. In the search field of Products (sales/inventory) i wanted to have Odoo also search by default the product code associated with a product (since some products have more than one seller and often people will request them by the vendor’s product code)

In my custom app in edited my myapp_view.xml to override the default search field for name with this:

<record model="ir.ui.view" id="metaxas_product_template_search">
  <field name="name"></field>
  <field name="model">product.template</field>
  <field name="inherit_id" ref="product.product_template_search_view"/>
  <field name="arch" type="xml">
    <xpath expr="//search/field[@name='name']" position="replace">
        <field name="name" string="Product" filter_domain="['|','|',('default_code','ilike',self),('name','ilike',self),('seller_ids.product_code','ilike',self)]"/>


Notice that the default Odoo search field is defined thus:

<field name="name" string="Product" filter_domain="['|',('default_code','ilike',self),('name','ilike',self)]"/>

According to Odoo docs , domains default to AND and if you want to use OR (or NOT) you prefix using ‘!’,’|’ etc. But what is not documented is how this prefix is applied. Adding a new third domain expresssion (‘field’,’operand’,’value) would default it to AND and basically screw your results. So i had to look into the source code with a GREP (ack rocks) and find out how Odoo does it and lo and behold, addonns/membership/membership_view.xml had the answer:

<field name="name"  filter_domain="['|','|',('name','ilike',self),('parent_id','ilike',self),('ref','=',self)]"/>

You need to prefix twice (or ,i assume, as many prefixes you require) Odoo docs need a lot of love still, despite significant progress.

Comments !