如何从Odoov10中删除此控制器错误



我编写了一个控制器来将数据推送到客户端。代码如下。任何人都可以提到这有什么错误吗?因为我收到这样的错误

File "/home/user/odoo/odoo10/custom/project/project_custom/controllers/main.py", line 21, in post_api_method
partners = request['import.order'].sudo().search_read([('customer', '=', 'TRADING COMPANY')])
File "/home/user/.local/lib/python2.7/site-packages/werkzeug/local.py", line 373, in <lambda>
__getitem__ = lambda x, i: x._get_current_object()[i]
TypeError: 'HttpRequest' object has no attribute '__getitem__'

我的代码就在下面:

# -*- coding: utf-8 -*-
from odoo import http
import requests
import json
from odoo.http import request
from odoo import report as odoo_report
import datetime
import pytz
import base64
import logging
_logger = logging.getLogger(__name__)
url = 'https://*********/api/********logistics/fillshipmentdetails***'
authentication = '129487521452XSDFG156235C6B353CD75QWERBVFGHJAA96AA99EDSJUITH7AAF65258F22871E7D415EB4A77CF7B4CB513A993680FC6053EAE6RT785YUIJ124'
class MyApi(http.Controller):
@http.route("/my/post/api/path", url=url, auth="none", type='http', method=['POST'], csrf=False, cors='*')
def post_api_method(self, *kw):
partners = request['import.order'].sudo().search_read([('customer', '=', 'TRADING COMPANY')])
headers = {'Content-Type': 'application/json'}
body = {'results': {"shipmentType": partners.ship_Type,
"shipperName": partners.customer.name,
"consigneeName": "*****",
"vslexparvlDate": "2019-03-05 05:55:13:000",
"vsldischlDate": "2019-04-02 05:55:13:000",
"docRecvByMailDate": "2019-03-05 05:55:13:000",
"orgDocRecvgDate": "2019-03-24 05:55:13:000",
"vesselArvlDate": "2019-03-19 05:55:13:000",
"bLAwbNumber": "*****",
"houseBL": "****",
"dischargingPort": "*****",
"landingPort": "*****",
"containerNumber": "*****",
"delOrderDate": "2019-03-29 05:55:13:000",
"delOrderNumber": "******",
"bayanNumber": "*****",
"bayanDate": "2019-03-30 05:55:13:000",
"containerType": "*****",
"dutyPaidDate": "2019-03-22 05:55:13:000",
"transportNTFTerminal": "***",
"transportDirCustomer": "***",
"demmurageDate": "2019-03-27 05:55:13:000",
"lastDetentionDate": "2019-03-27 05:55:13:000",
"eIRReturnToShipLine": "****",
"eventUpdateStatus": "Delivered"
}}
response = requests.post(url, json.dumps(body), headers=headers)
return response

提供给键的所有值都是演示数据。前两个键值只是正确的键值。

您可以使用绑定到当前请求的环境访问 ORM 模型 (http.request.env(。

partners = request.env['import.order'].sudo().search_read([('customer', '=', 'TRADING COMPANY')])

相关内容

  • 没有找到相关文章

最新更新