Search code examples
pythonodoo-8

How to check whether admin or user is logged in odoo


Currently i am developing a module in odoo. In my module users can edit there own data only, but admin can do anything. But with my code admin also can't edit. If i know admin is logged in, then i can bypass admin account. So how to know when admin is logged in?

def write(self, vals):
    //if admin is logged in i need to bypass the below code//
    if self.create_uid != self.env.user:
        raise Warning('You can not able to edit this document as this is not your record')
    return super(request_room, self).write(vals)

Solution

  • You'd want to use the super_user (admin) id. Probably the id = 1 The code below would do the trick.

    from openerp import SUPERUSER_ID
    def write(self, vals):
        //if admin is logged in i need to bypass the below code//
        if self.create_uid != self.env.user and self.create_uid != SUPERUSER_ID:
            raise Warning('You can not able to edit this document as this is not your record')
        return super(request_room, self).write(vals)