Odoo Help

Welcome!

This community 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.

0

How can I search products by ancestor category?

By
Alexandre Fayolle - Camptocamp
on 9/15/14, 4:06 AM 1,560 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..

Eric
on 9/24/14, 2:02 AM
0
Eric
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>

</field>

</field>

</record>

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>

</field>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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