diff --git a/yuthon_base/__manifest__.py b/yuthon_base/__manifest__.py index fc9fdca6f..00b5706a4 100644 --- a/yuthon_base/__manifest__.py +++ b/yuthon_base/__manifest__.py @@ -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', diff --git a/yuthon_base/data/res_users_data.xml b/yuthon_base/data/res_users_data.xml new file mode 100644 index 000000000..3f34e3b77 --- /dev/null +++ b/yuthon_base/data/res_users_data.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/yuthon_base/models/res_users.py b/yuthon_base/models/res_users.py index e8026b390..93f65c94c 100644 --- a/yuthon_base/models/res_users.py +++ b/yuthon_base/models/res_users.py @@ -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)