# -*- coding: utf-8 -*- from odoo import api, fields, models, _ class ModelAccessRights(models.Model): """This class is used to detect, which all options want to hide from the specified group and model""" _name = 'access.right' _inherit = 'mail.thread' _description = 'Manage Modules Access Control' _rec_name = 'model_id' model_id = fields.Many2one('ir.model', ondelete='cascade', required=True, help="select the model") groups_id = fields.Many2one('res.groups', required=True, help="select the group") is_delete = fields.Boolean(string="Delete", help="hide the delete option") is_export = fields.Boolean(string="Export", help="hide the 'Export All'" " option from list view") is_create_or_update = fields.Boolean(string="Create/Update", help="hide the create option from list" " as well as form view") is_archive = fields.Boolean(string="Archive/UnArchive", help="hide the archive option") @api.model def hide_buttons(self): """This function contains a query that detects which all options want to hide, in which model,and to which user groups""" access_right_rec = self.sudo().search_read([], ['model_id', 'is_delete', 'is_export', 'is_create_or_update', 'is_archive', 'groups_id']) for dic in access_right_rec: model = self.env['ir.model'].sudo().browse(dic['model_id'][0]).model group_name = self.env['ir.model.data'].sudo().search([ ('model', '=', 'res.groups'), ('res_id', '=', dic['groups_id'][0]) ]).name module_name = self.env['ir.model.data'].sudo().search([ ('model', '=', 'res.groups'), ('res_id', '=', dic['groups_id'][0]) ]).module dic.update({ 'model': model, 'group_name': group_name, 'module': module_name }) return access_right_rec # @api.model # def hide_buttons(self): # """This function contains a query that detects which all options want # to hide, in which model,and to which user groups""" # access_right_rec = self.sudo().search_read([], ['model_id', 'is_delete', # 'is_export', # 'is_create_or_update', # 'is_archive', # 'groups_id']) # for dic in access_right_rec: # model = self.env['ir.model'].sudo().browse(dic['model_id']).model # group_name = self.env['ir.model.data'].sudo().search([ # ('model', '=', 'res.groups'), # ('res_id', '=', dic['groups_id']) # ]).name # module_name = self.env['ir.model.data'].sudo().search([ # ('model', '=', 'res.groups'), # ('res_id', '=', dic['groups_id']) # ]).module # dic.update({ # 'model': model, # 'group_name': group_name, # 'module': module_name # }) # return access_right_rec # class AccessRightCleanup(models.Model): # _name = 'access.right.cleanup' # 定义一个新的模型名 # _description = 'Access Right Cleanup' # @api.model # def _module_uninstall(self): # """在模块卸载时执行清理操作""" # super(AccessRightCleanup, self)._module_uninstall() # # 这里执行你的清理逻辑 # # # 获取access.right模型的所有记录 # access_rights = self.env['access.right'].search([]) # for access_right in access_rights: # # 删除access.right模型的所有记录 # access_right.unlink() # # # 查找所有关联到access.right模型的关注者记录 # followers = self.env['mail.followers'].search([('res_model', '=', 'access.right')]) # for follower in followers: # # 删除关注者记录 # follower.unlink() # # # # 示例:删除自定义数据表(确保先检查外键约束等) # # self.env.cr.execute('DROP TABLE IF EXISTS access_right CASCADE;') # # # 其他清理工作...