跳至内容
菜单
此问题已终结
1 回复
159 查看

Hello,

I'm working on integrating Odoo with HubSpot and need to synchronize user data including their access rights/permissions. While I can successfully fetch basic user information, I'm unable to retrieve the security groups and permissions assigned to users.

My Goal: Fetch employees with their specific access rights (like "Sales Administrator", "Accounting User", "Bank Validate", etc.) via the External API to map them to corresponding roles in HubSpot.

What I've Tried:

Basic user query works:


users = odoo.call_kw('res.users', 'search_read', 
    [[['active', '=', True]]], 
    {'fields': ['name', 'login', 'email']})

Attempting to get groups_id field fails:


# This doesn't return groups_id data
users = odoo.call_kw('res.users', 'search_read', 
    [[['id', 'in', user_ids]]], 
    {'fields': ['id', 'name', 'groups_id']})

Is it possible to fetch user security groups via External API?



形象
丢弃
最佳答案

Hi,

In Odoo, the groups_id field on res.users is a many2many relation to res.groups. When you query it with search_read, Odoo only returns the IDs of the groups, not their names or descriptions. That’s why your call seems to “fail” — it actually gives back a list of group IDs like [3, 42, 56].

To get the labels (e.g. “Sales Administrator”, “Accounting User”), you need to make a second call to res.groups with those IDs:

# 1. Fetch users with group IDs

users = odoo.call_kw('res.users', 'search_read',

    [[['active', '=', True]]],

    {'fields': ['id', 'name', 'login', 'email', 'groups_id']}

)


# 2. Collect all group IDs across users

group_ids = {gid for user in users for gid in user['groups_id']}


# 3. Fetch group details

groups = odoo.call_kw('res.groups', 'read',

    [list(group_ids)],

    {'fields': ['id', 'name', 'category_id']}

)


# 4. Map group IDs to names for easy lookup

group_map = {g['id']: g['name'] for g in groups}


# 5. Attach readable group names to users

for user in users:

    user['group_names'] = [group_map[gid] for gid in user['groups_id']]


Hope it helps.

形象
丢弃