Помните, что этот контроллер работает.
class Jsontest(http.Controller):
@http.route('/api/testjson', auth='public', csrf=False, type='json', methods=['POST'])
def recive_json(self, **kw):
result_insert_record = http.request.env['sale.order'].sudo().create({
'name': 'test sale order 4',
'partner_id': 20,
'order_line': [
(0, 0, {
'product_id': 28, #el id en tabla product va al de product_template
'product_uom_qty':2}),
(0, 0, {
'product_id': 27,
'product_uom_qty':2})]
})
return result_insert_record
Мне нужно отправить json на параметр (кВт).
Я изменил свой контроллер на
class Jsontest(http.Controller):
@http.route('/api/testjson', auth='public', csrf=False, type='json', methods=['POST'])
def recive_json(self, **kw):
result_insert_record = http.request.env['sale.order'].sudo().create(kw)
return result_insert_record
и отправить это json и работает.
JSON:
{ "params": {
"name": "test sale order 6",
"partner_id": 20
}
}
Ответ:
{
"jsonrpc": "2.0",
"id": null,
"result": "sale.order(36,)"
}
Теперь проблема возникает, когда я хочу создать порядок со строками
я пробовал эту последовательность json, но она дает мне следующую ошибку
json
{ "params": {
"name": "test sale order 7",
"partner_id": 20,
"order_line": [
{
"product_id": 28,
"product_uom_qty":22
}
]
}
}
ошибка
{
"jsonrpc": "2.0",
"id": null,
"error": {
"code": 200,
"message": "Odoo Server Error",
"data": {
"name": "builtins.KeyError",
"debug": "Traceback (most recent call last):\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\http.py\", line 653, in _handle_exception\n return super(JsonRequest, self)._handle_exception(exception)\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\http.py\", line 312, in _handle_exception\n raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\tools\\pycompat.py\", line 87, in reraise\n raise value\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\http.py\", line 695, in dispatch\n result = self._call_function(**self.params)\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\http.py\", line 344, in _call_function\n return checked_call(self.db, *args, **kwargs)\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\service\\model.py\", line 97, in wrapper\n return f(dbname, *args, **kwargs)\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\http.py\", line 337, in checked_call\n result = self.endpoint(*a, **kw)\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\http.py\", line 939, in __call__\n return self.method(*args, **kw)\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\http.py\", line 517, in response_wrap\n response = f(*args, **kw)\n File \"c:\\users\\gustavo\\desktop\\custom_addons\\jsontest\\controllers\\controllers.py\", line 10, in recive_json\n result_insert_record = http.request.env['sale.order'].sudo().create(kw)\n File \"c:\\program files (x86)\\odoo 11.0\\server\\odoo\\addons\\sale\\models\\sale.py\", line 302, in create\n result = super(SaleOrder, self).create(vals)\n File \"c:\\program files (x86)\\odoo 11.0\\server\\odoo\\addons\\mail\\models\\mail_thread.py\", line 237, in create\n thread = super(MailThread, self).create(values)\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\models.py\", line 3426, in create\n record = self.browse(self._create(old_vals))\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\models.py\", line 3573, in _create\n field.write(self.with_context(rel_context), vals[name], create=True)\n File \"C:\\Program Files (x86)\\Odoo 11.0\\server\\odoo\\fields.py\", line 2300, in write\n if act[0] == 0:\nKeyError: 0\n",
"message": "0",
"arguments": [
0
],
"exception_type": "internal_error"
}
}
}
Кто-нибудь знает, как должен выглядеть JSON для создания заказа со строками?
Спасибо !!!