diff --git a/doc/howtos/backend.rst b/doc/howtos/backend.rst index e723017d455..f99ae98df58 100644 --- a/doc/howtos/backend.rst +++ b/doc/howtos/backend.rst @@ -1752,7 +1752,7 @@ JSON-RPC Library ---------------- The following example is a Python program that interacts with an Odoo server -with the libraries ``urllib2`` and ``json``:: +with the standard Python libraries ``urllib2`` and ``json``:: import json import random @@ -1788,6 +1788,31 @@ with the libraries ``urllib2`` and ``json``:: } idea_id = call(url, "object", "execute", DB, uid, PASS, 'idea.idea', 'create', args) +Here is the same program, using the library +`jsonrpclib `:: + + import jsonrpclib + + # server proxy object + url = "http://%s:%s/jsonrpc" % (HOST, PORT) + server = jsonrpclib.Server(url) + + # log in the given database + uid = server.call(service="common", method="login", args=[DB, USER, PASS]) + + # helper function for invoking model methods + def invoke(model, method, *args): + args = [DB, uid, PASS, model, method] + list(args) + return server.call(service="object", method="execute", args=args) + + # create a new idea + args = { + 'name' : 'Another idea', + 'description' : 'This is another idea of mine', + 'inventor_id': uid, + } + idea_id = invoke('idea.idea', 'create', args) + Examples can be easily adapted from XML-RPC to JSON-RPC. .. note::