The method has_group
in the model res.users
is helpful for checking if a user belongs to a specific group.
For example, if we need to check if a user is a salesman in the system, the code should look like this:
Another method that is useful when need to check the current user's group membership is user_has_groups
. This method is available in all models and it returns True
if the user has at least one of the provided groups in groups
not preceded by !
and is not a member of any of the groups in groups
preceded by !
.
An example of this method that will confirm that the current active user is a salesman but not a purchase manager is the following: