如何在继承控制器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>', type='http', auth="user")
@serialize_exception
def download_document(self, **kw):

但是当我在另一个模块中使用action来download_document时,它仍然使用继承类的函数。

我希望这个函数只在这个模块的继承类中使用,而不是在所有地方使用,那么我该怎么做呢?

其他模块将使用它们所依赖的模块的函数。因此,在你想要使用被覆盖函数的模块的manifest中,请确保依赖于my_module。

__manifest__.py
.
.
.
'depends': [
'my_module',
],
.
.

为了解决这种情况,我只使用condition并调用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)

最新更新