Odoo control access with the search_read method
top of page
  • Writer's pictureTek Siong, Hock

Odoo control access with the search_read method

Updated: Apr 5, 2023

If you can't build a dynamic access to the partner or product with the standard record rules, perhaps you may use the search_read method, which offer a more flexible and dynamic way to control the domain.

Example below is in the example by inherit the res.partner and implement the search_read method to generate the dynamic domain.

@api.model
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
    user = self.env.user
    user_is_billing_manager = user.has_group('account.group_account_manager')
    user_is_billing_user = user.has_group('account.group_account_invoice')

    if user_is_billing_manager:
        domain = []

    elif user_is_billing_user:
        domain = [('is_vip', '=', True), ('cs_rep.id', '=', user.id)]
    
    domain = expression.AND([domain, add_domain])
    
    return super(ResPartner, self).search_read(domain=domain, fields=fields, offset=offset, limit=limit,
                                               order=order)
90 views0 comments

Recent Posts

See All

Odoo Element Cannot be Located in Parent View

Sometimes, after you've added a new field to the existing view, by inheriting the view, you may encountered the following error, when upgrading the module. Element 'XXXXX' cannot be located in parent

bottom of page