I am trying to add an order line to an existing sales order via XMLRPC
I am trying this:
r = api.execute_kw(db, uid, pwd, 'sale.order', 'write', [[sc]], { 'order_line': (0, '_', {'product_id': id, 'product_uom_qty': qty}) })
Where id
, qty
are integer numbers, and sc
is the integer number with the ID
of the sale order.
I get this error:
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'>
I see two mistakes here. One was already pointed at by Sanaullah Khan: A write on one2many
or many2many
fields has to be a list of "triplets".
And your call isn't correct. You're using args
and kwargs
on the call. The values parameter of write()
is not a keyword argument/parameter. So get it into the args
:
r = api.execute_kw(
db, uid, pwd, 'sale.order', 'write',
[[sc], {'order_line': \ # args
[(0, '_', {'product_id': id, 'product_uom_qty': qty})]}],
{}) # kwargs