【发布时间】:2019-07-17 20:42:30
【问题描述】:
我需要访问 Odoo 10 中的 /web/session/authenticate 方法(来自 Vue 应用程序),但我需要进行微小的自定义。 Based on another post 我可以看到应该可以覆盖 Odoo 的内置控制器,所以我在自定义控制器中,在自定义模块中:
from odoo import http
from odoo.http import request
from odoo.addons.web.controllers.main import Session
class Session(Session):
@http.route('/web/session/authenticate', type='json', auth="none", cors="*")
def authenticate(self, db, login, password, base_location=None):
print("custom authentication method called")
request.session.authenticate(db, login, password)
return request.env['ir.http'].session_info()
与existing source code 相比,可以看出我所做的只是添加CORS 支持(我在Vue 应用程序中的axios POST 需要该路由)
我没有收到错误,但由于某种原因,Odoo 从未调用过我的自定义代码。也许这与我的模块加载顺序有关?
【问题讨论】:
-
另外..请记住,此时没有数据库上下文,因为没有会话。我注意到当没有已知数据库并且 db_monodb() 无法确定数据库时,Odoo 使用“nodb_routing_map”来确定有效路由。所以也许这也会阻止任何控制器在自定义模块中工作??
标签: odoo-10