6

I have extended model stock.picking with a new method called do_new_transfer_xmlrpc which enables a basic new_transfer from XMLRPC.

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

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

I try to call that method using:

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

But I get:

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'>

Is the used call method properly written?

M.E.
  • 4,955
  • 4
  • 49
  • 128
  • seam that odoo cannot find your method how did you add it?! – Charif DZ Jan 25 '18 at 08:21
  • @Cherif I have included the python file I use to extend it. It is included in __init__.py as import. – M.E. Jan 26 '18 at 00:57
  • Ithink you are doing some thing wrong what i suggest is to create a dummy button to call this method when you found it using the button you can call it xml-rpc – Charif DZ Jan 26 '18 at 09:05
  • and the file.py is it in a subfolder and you forgot to import it in the init of the container folder .... – Charif DZ Jan 26 '18 at 09:07
  • No I did not forgot to import anything as I use a print statement in that file and I can see it when invoking odoo. so the source is being loaded. – M.E. Jan 26 '18 at 09:17
  • So you mean that you can call this function from a button in the view?!! – Charif DZ Jan 26 '18 at 16:02
  • I mean that the source code which extends stock_picking is loaded so is the new method. The issue was in the way the remote method was being invoked. – M.E. Jan 27 '18 at 20:42

2 Answers2

7

This is the right syntax:

api.execute_kw(db, uid, pwd, 'stock.picking', 'do_new_transfer_xmlrpc', [int(picking_id)])
M.E.
  • 4,955
  • 4
  • 49
  • 128
0

You can try the below code.

leave_data = models.execute_kw(db, uid, password,'hr.leave', 'get_available_leaves',[10],{'employee_id':1})
print("leave_data=",leave_data)

the code is will call the method 'get_available_leaves' which is having paremeters of employee_id. 10 is the id of the record.

actual method :

def get_available_leaves(self, employee_id):
Syscall
  • 19,327
  • 10
  • 37
  • 52
Nivas M
  • 11
  • 1
  • 3