top of page

Odoo control access with the search_read method

Writer: Tek Siong, Hock
Tek Siong, Hock
Apr 4, 2023
1 min read

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)
 
 
 

Recent Posts

See All
Integrating EasyParcel with Odoo

Connect Odoo to EasyParcel to fetch live courier rates and create shipments from the website checkout and from sales orders. Benefits Live rates from several couriers (Aramex, J&T, DHL eCommerce, Laza

 
 
 

Comments


Subscribe Form

  • facebook
  • linkedin

©2019 by Excelroot Technology Sdn Bhd.

bottom of page