Odoo Help


How can I search products by ancestor category?

Alexandre Fayolle - Camptocamp
on 9/15/14, 4:06 AM 2,741 views

I would like to provide a search filter enabling the user to search products by ancestor category. Workflow would be as follows:

* the user displays the Product tree view

* he types in the start of a category name, and gets a proposition of matching categories (including those who do not have products directly linked), under a "category" or "ancestor category" filter name

* when he selects the category in the filter, the list of products is updated to match products under that category or any child category.


I naively tried:

          <filterd name="category_id"
                  string="Ancestor Category"
                  filter_domain="['|', ('category_id', '=', self), (category_id', 'child_of', self)]"/>

but this does not work ("empty" categories are not proposed)

[Edit] I can probably hack something with a function field, if I have to but this sound clumsy for a needs which seems basic.

Any luck on this? I'm having the same problem..

on 9/24/14, 2:02 AM
On 10/9/14, 4:05 AM

There were two ways of solving this question:

  1. You create a module (there are some tutorials around explaining that) and then you install it.

The code for the view would be:

<record id="view_product_search_child_categories" model="ir.ui.view">

<field name="name">product.search.categories</field>

<field name="model">product.product</field>

<field name="inherit_id" ref="product.product_search_form_view" />

<field name="arch" type="xml">

<field name="categ_id" position="attributes">

<attribute name="operator">child_of</attribute>




Or the other option:

  1. You create a view directly from within OpenERP interface. In my case I did:
    • Enable the Technical features of my admin user.
    • Go to Settings>Technical>User Interface>Views>Create:
      • View name: product.search.categories
      • View type: (it will display Tree but after saving will change to Search)
      • Object: product.product
      • Child Field: empty
      • Inherited view: product.search.form
      • External ID: empty

In the architecture write:

<?xml version="1.0"?>

<field name="categ_id" position="attributes">

<attribute name="operator">child_of</attribute>


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 9/15/14, 4:06 AM
Seen: 2741 times
Last updated: 3/16/15, 8:10 AM