Odoo14 重写Model中的方法
1 # 重写Model方法 2 # get_formview_id:分享出去的链接跳转到访问模型某条记录,指定form视图展示 3 def get_formview_id(self, access_uid=None): 4 if access_uid: 5 self_sudo = self.with_user(access_uid) 6 else: 7 self_sudo = self 8 if self_sudo.check_access_rights('read', raise_exception=False): # 权限校验 9 return super(HrEmployeePrivate, self).get_formview_id(access_uid=access_uid) 10 return self.env.ref('hr.hr_employee_public_view_form').id 11 12 # get_access_action:返回分享出去的链接跳转到访问模型某条记录时的action 13 def get_access_action(self, access_uid=None): 14 self.ensure_one() 15 user = access_uid and self.env['res.users'].sudo().browse(access_uid) or self.env.user 16 if not self.sale_order_template_id or (not user.share and not self.env.context.get('force_website')): 17 return super(SaleOrder, self).get_access_action(access_uid) 18 return { 19 'type': 'ir.actions.act_url', 20 'url': self.get_portal_url(), 21 'target': 'self', 22 'res_id': self.id, 23 } 24 25 # 模型中添加"active = fields.Boolean(default=True)"字段后,模型自动异常active为False的记录;并且自动在action中添加Archived与Restore动作将active字段标记为False和恢复为True 26 # action_archive就是Archived动作,如果业务需要你可以重写它 27 def action_archive(self): 28 """ Set (x_)active=False on a recordset, by calling toggle_active to 29 take the corresponding actions according to the model 30 """ 31 return self.filtered(lambda record: record[self._active_name]).toggle_active() 32 33 # action_unarchive是Restore动作,如果业务需要你可以重写它 34 def action_unarchive(self): 35 """ Set (x_)active=True on a recordset, by calling toggle_active to 36 take the corresponding actions according to the model 37 """ 38 return self.filtered(lambda record: not record[self._active_name]).toggle_active() 39
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?