Search Here

Show Filtered Records in Tree View Based on Active Login User

In Odoo to show records that are related to Active User is not a big deal. First understand what we are going to do here.

Show Filtered Records in Tree View Based on Active Login User

Problem Statement

Let say we have a company and in that company we have different active user related to different department. And we want to display some data or records in a tree view or list view according to active user department, when some one clicks on related menu. To achieve this goal we need to create dynamic domain on action window.

Read More: How to Create Form and Tree View in Odoo

Solution

To put domain on action window we need a computed filed in Odoo 8 or function field in older version of Odoo, in that computed field we need to create two method first one for computed field and second one for search.

Read More: How to Create Window Action and Menu Item in Odoo

show_filtered_records_in_tree_view.py

Code Description

In above code we have created a computed field, and in computed field we used search method. Notice search method takes three parameter self, operator and operand. And in that method we return records that are related to active user department.

Usage of computed field as domain in action window

To display records related to active user we need to put this computed field "search_ids" in action window below view_mode as a domain.


show_filtered_records_in_tree_view.xml


Post a Comment

6 Comments

  1. I really need this. Thanks dude

    ReplyDelete
  2. Just Perfect !!! Thank you !

    ReplyDelete
  3. Can you explain the logic behind the use of a computed field (with search function) in a domain and why you have to put equal to 1 or the meaning on putting equal to 1.

    It works really well! Thanks for your help!

    ReplyDelete
  4. Thanks for your comment, Search function will not work without computed field, that's why i have used this computed field. And putting 1 in domain means that every time its being called whenever user clicked on menu.

    ReplyDelete