问题描述
我的核心控制器类:
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)