Tek Siong, Hock

Jan 7, 20231 min

Odoo - Bypass record rule in the python codes

What are the occasions when you need to bypass the record rule?

a) Certain fields are only accessible by certain group of users (record rule) and if the restricted field value are updated by all users action.

b) User's action will trigger the retrieving of data by search that may have the record rules that are restricted to the user.

The solution is simple by using sudo().

Eg,

self.env['account.invoice'].sudo().search(invoice_domain)

    120
    0