Problem Statement

Solution

search_ids = fields.Char(compute="_compute_search_ids",search='search_ids_search')

@api.one @api.depends('department_id') def _compute_search_ids(self):

print('View My Department CLO ACL') def search_ids_search(self, operator, operand):

obj = self.env['your.model'].search([('department_id','=',self.env.user.department_id.id)]).ids return [('id','in',obj)]

Code Description

Usage of computed field as domain in action window

search_ids

<field name="view_type">form</field> <field name="view_mode">tree,form</field> <field name="domain">[('search_ids ','=',1)]</field>

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.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 aaccording to active user department, when some one clicks on related menu. To achieve this goal we need to create dynamic domain on action window.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.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.To display records related to active user we need to put this computed field "" in action window below view_mode as a domain.