我正在尝试通过XMLRPC
向现有销售订单添加订单行我正在尝试这个:
r = api.execute_kw(db, uid, pwd, 'sale.order', 'write', [[sc]], { 'order_line': (0, '_', {'product_id': id, 'product_uom_qty': qty}) })
id
,qty
是整数,sc
是销售订单ID
的整数。
我收到此错误:
Fault: <Fault 1: 'Traceback (most recent call last):\n File "/usr/lib/python2.7/dist-packages/odoo/service/wsgi_server.py", line 56, in xmlrpc_return\n result = odoo.http.dispatch_rpc(service, method, params)\n File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 118, in dispatch_rpc\n result = dispatch(method, params)\n File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 38, in dispatch\n res = fn(db, uid, *params)\n File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 157, in execute_kw\n return execute(db, uid, obj, method, *args, **kw or {})\n File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 101, in wrapper\n return f(dbname, *args, **kwargs)\n File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 164, in execute\n res = execute_cr(cr, uid, obj, method, *args, **kw)\n File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 153, in execute_cr\n return odoo.api.call_kw(recs, method, args, kw)\n File "/usr/lib/python2.7/dist-packages/odoo/api.py", line 689, in call_kw\n return call_kw_multi(method, model, args, kwargs)\n File "/usr/lib/python2.7/dist-packages/odoo/api.py", line 680, in call_kw_multi\n result = method(recs, *args, **kwargs)\nTypeError: write() got an unexpected keyword argument \'order_line\'\n'>
答案 0 :(得分:1)
您传递给该字段的值格式不正确。它应该是一个元组列表而不仅仅是一个元组。
尝试将以下值传递给它。
{ 'order_line': [(0, '_', {'product_id': id, 'product_uom_qty': qty})]}
希望它能够解决你所面临的问题。
答案 1 :(得分:1)
我在这里看到两个错误。 Sanaullah Khan已经指出了一个问题:在one2many
或many2many
字段上写一个必须是“三元组”列表。
你的电话不正确。您在通话中使用args
和kwargs
。 write()
的values参数不是关键字参数/参数。所以进入args
:
r = api.execute_kw(
db, uid, pwd, 'sale.order', 'write',
[[sc], {'order_line': \ # args
[(0, '_', {'product_id': id, 'product_uom_qty': qty})]}],
{}) # kwargs