From 8225ef6c995ae302b61020d27c14e7bfbb11109d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 1 Mar 2012 11:30:49 +0100 Subject: [PATCH] [ADD] small doc for Connection#rpc bzr revid: xmo@openerp.com-20120301103049-u2b208awbv6e67xb --- doc/source/rpc.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/source/rpc.rst b/doc/source/rpc.rst index 1192b28971f..672173f6469 100644 --- a/doc/source/rpc.rst +++ b/doc/source/rpc.rst @@ -242,3 +242,31 @@ asynchronously (and using indexes). Low-level API: RPC calls to Python side --------------------------------------- +While the previous section is great for calling core OpenERP code +(models code), it does not work if you want to call the Python side of +openerp-web. + +For this. a lower-level API is available on +:js:class:`openerp.web.Connection` objects (usually available through +``openerp.connection``): the ``rpc`` method. + +This method simply takes an absolute path (which is the combination of +the Python controller's ``_cp_path`` attribute and the name of the +method yo want to call) and a mapping of attributes to values (applied +as keyword arguments on the Python method [#]_). This function fetches +the return value of the Python methods, converted to JSON. + +For instance, to call the ``eval_domain_and_context`` of the +:class:`~web.controllers.main.Session` controller: + +.. code-block:: javascript + + openerp.connection.rpc('/web/session/eval_domain_and_context', { + domains: ds, + contexts: cs + }).then(function (result) { + // handle result + }); + +.. [#] except for ``context``, which is extracted and stored in the + request object itself.