@@ -8,6 +8,7 @@
|
||||
'license': 'LGPL-3',
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'data/res_users_data.xml',
|
||||
'views/system_version_views.xml',
|
||||
'views/system_logs_views.xml',
|
||||
'views/ir_cron_act_views.xml',
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="0">
|
||||
<!-- 从默认用户模板中移除财务管理员权限组,新建用户不再默认带这些权限 -->
|
||||
<record id="base.default_user" model="res.users">
|
||||
<field name="groups_id" eval="[(3, ref('account.group_account_manager')), (3, ref('account.group_account_invoice'))]"/>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -5,36 +5,10 @@ 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