Problem StatementLet 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.
SolutionTo 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.
print('View My Department CLO ACL')
def department_clo_acl_ids_search(self, operator, operand):
clo_acl_obj = self.env['obe.clo.acl'].search([('department_id','=',self.env.user.faculty_id.department_id.id)]).ids
Code DescriptionIn 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 windowTo display records related to active user we need to put this computed field "department_clo_acl_ids" in action window below view_mode as a domain.