如何解决如何覆盖仅在此模块中使用的继承控制器 Odoo 12 中的功能
我的核心控制器类:
class ReportController(http.Controller):
@http.route('/report/download_document/<reportname>/<docids>',type='http',auth="user")
@serialize_exception
def download_document(self,**kw):
我的继承类:
from odoo.addons.my_module.controllers.main import ReportController as RC
class ReportControllerProject(RC):
# Override method: download_document in my_module
@http.route('/report/download_document/<reportname>/<docids>',**kw):
但是当我在另一个模块中使用 action to download_document 时,它仍然使用了继承类的功能。
我希望这个函数只在这个模块的继承类中使用,而不是到处都使用,那我该怎么办?
解决方法
其他模块将使用它们所依赖的模块的功能。 因此,在要使用覆盖函数的模块的清单中,请确保依赖于 my_module。
__manifest__.py
.
.
.
'depends': [
'my_module',],.
.
,
为了解决这种情况,我只是使用条件并调用 super() 函数来执行这个覆盖函数
from odoo.addons.my_module.controllers.main import ReportController as RC
class ReportControllerProject(RC):
# Override method: download_document in my_module
@http.route('/report/download_document/<reportname>/<docids>',type='http',auth="user")
@serialize_exception
def download_document(self,**kw):
*some code here*
if <condition>:
*some code here*
return *something here*
else:
return super(ReportControllerProject,self).download_document(**kw)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。