gpt4 book ai didi

python - 如何从 Odoo v10 中删除此 Controller 错误

转载 作者:太空宇宙 更新时间:2023-11-04 04:02:05 27 4
gpt4 key购买 nike

我写了一个 Controller 来将数据推送到客户端。代码如下。任何人都可以提及这有什么错误吗?因为我收到类似

的错误
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

赋予键的所有值都是演示数据。只有前两个键值是正确的。

最佳答案

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

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

关于python - 如何从 Odoo v10 中删除此 Controller 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58077998/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com