我需要在Odoo上创建一个自定义控制器,以从特定任务中获取信息。而且我也可以得出结果。但是现在我遇到了一个问题。
客户端需要检索具有特定字段的信息。
例如, 客户端需要使用跟踪号来检索信息,并且数据也必须为JSON格式。如果跟踪号为15556456356,则网址应为 www.customurl.com/dataset/ 15556456356
答案 0 :(得分:0)
该URL的路由应为TagCount >: (String,Option[Int])
,基本上该方法应如下所示:
def toSet[B >: A]: Set[B]
此方法接受@http.route('/dataset/<string:tracking_number>', type='http or json', auth="user or public")
请求并返回import json
from odoo import http
from odoo.http import Response, request
class tracking(http.Controller):
# if user must be authenticated use auth="user"
@http.route('/dataset/<string:tracking_number>', type='http', auth="public")
def tracking(self, tracking_number): # use the same variable name
result = # compute the result with the given tracking_number and the result should be a dict to pass it json.dumps
return Response(json.dumps(result), content_type='application/json;charset=utf-8',status=200)
响应,如果客户端发送http
请求,则应更改json
。不要忘记在json
中导入文件。
让我们举个例子吧,我想通过在type='json'
中给出__init___.py
来返回有关sale.order
的一些信息:
ID
因此,当我使用浏览器输入以下网址时:URL
: