菜单权限
This commit is contained in:
@@ -5,10 +5,36 @@ from odoo import api, models
|
||||
class ResUsers(models.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super().default_get(fields_list)
|
||||
# 新建用户时默认不勾选财务管理员权限组
|
||||
if 'groups_id' in res:
|
||||
group_manager = self.env.ref('account.group_account_manager', raise_if_not_found=False)
|
||||
group_invoice = self.env.ref('account.group_account_invoice', raise_if_not_found=False)
|
||||
groups_to_remove = set()
|
||||
if group_manager:
|
||||
groups_to_remove.add(group_manager.id)
|
||||
if group_invoice:
|
||||
groups_to_remove.add(group_invoice.id)
|
||||
if groups_to_remove:
|
||||
# groups_id 在 default_get 中可能是 [(6, 0, [ids])] 或 [ids] 格式
|
||||
groups_value = res['groups_id']
|
||||
if groups_value and isinstance(groups_value[0], (list, tuple)):
|
||||
# [(6, 0, [ids])] 格式
|
||||
for i, cmd in enumerate(groups_value):
|
||||
if cmd[0] == 6:
|
||||
filtered_ids = [gid for gid in cmd[2] if gid not in groups_to_remove]
|
||||
groups_value[i] = (6, 0, filtered_ids)
|
||||
else:
|
||||
# [ids] 格式
|
||||
res['groups_id'] = [gid for gid in groups_value if gid not in groups_to_remove]
|
||||
return res
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
users = super().create(vals_list)
|
||||
# 新建用户后移除财务管理员权限组
|
||||
# 新建用户后再次确保移除财务管理员权限组
|
||||
groups_to_remove = []
|
||||
group_manager = self.env.ref('account.group_account_manager', raise_if_not_found=False)
|
||||
group_invoice = self.env.ref('account.group_account_invoice', raise_if_not_found=False)
|
||||
|
||||
Reference in New Issue
Block a user