Odoo 10 - 来自XMLRPC的呼叫方法

时间:2018-01-25 03:05:05

标签: xml-rpc odoo-10 odoo

我使用名为stock.picking的新方法扩展了模型do_new_transfer_xmlrpc,该方法启用了来自XMLRPC的基本new_transfer。

class Picking(models.Model):
  _inherit = 'stock.picking'

  @api.multi
  def do_new_transfer_xmlrpc(self):
    print 'DEBUG'
    self.do_transfer()
    return ['OK', '']

我尝试使用以下方法调用该方法:

api.execute_kw(db, uid, pwd, 'stock.picking', 'do_new_transfer_xmlrpc', [[int(picking_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 685, in call_kw\n    method = getattr(type(model), name)\nAttributeError: type object \'stock.picking\' has no attribute \'do_new_transfer_xmlrpc\'\n'>

使用的调用方法是否正确写入?

1 个答案:

答案 0 :(得分:6)

这是正确的语法:

api.execute_kw(db, uid, pwd, 'stock.picking', 'do_new_transfer_xmlrpc', [int(picking_id)])