~openerp-community/openobject-doc/ksa-openobject-doc-6.0

« back to all changes in this revision

Viewing changes to i18n/ru/source/developer/6_22_XML-RPC_web_services/index.rst

  • Committer: Don Kirkby
  • Date: 2011-02-21 20:46:11 UTC
  • mfrom: (433.1.53 openobject-doc)
  • Revision ID: donkirkby+launpd@gmail.com-20110221204611-1ykt6dmg4k3gh5dh
[MERGE] revisions 477 to 486 from the 5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
.. i18n: XML-RPC Web services
 
3
.. i18n: ====================
 
4
..
 
5
 
 
6
XML-RPC Web services
 
7
====================
 
8
 
 
9
.. i18n: XML-RPC is known as a web service. Web services are a set of tools that let one build distributed applications on top of existing web infrastructures. These applications use the Web as a kind of "transport layer" but don't offer a direct human interface via the browser.[1] Extensible Markup Language (XML) provides a vocabulary for describing Remote Procedure Calls (RPC), which is then transmitted between computers using the HyperText Transfer Protocol (HTTP). Effectively, RPC gives developers a mechanism for defining interfaces that can be called over a network. These interfaces can be as simple as a single function call or as complex as a large API.
 
10
..
 
11
 
 
12
XML-RPC is known as a web service. Web services are a set of tools that let one build distributed applications on top of existing web infrastructures. These applications use the Web as a kind of "transport layer" but don't offer a direct human interface via the browser.[1] Extensible Markup Language (XML) provides a vocabulary for describing Remote Procedure Calls (RPC), which is then transmitted between computers using the HyperText Transfer Protocol (HTTP). Effectively, RPC gives developers a mechanism for defining interfaces that can be called over a network. These interfaces can be as simple as a single function call or as complex as a large API.
 
13
 
 
14
.. i18n: XML-RPC therefore allows two or more computers running different operating systems and programs written in different languages to share processing. For example, a Java application could talk with a Perl program, which in turn talks with Python application that talks with ASP, and so on. System integrators often build custom connections between different systems, creating their own formats and protocols to make communications possible, but one can often end up with a large number of poorly documented single-use protocols. The RPC approach spares programmers the trouble of having to learn about underlying protocols, networking, and various implementation details.
 
15
..
 
16
 
 
17
XML-RPC therefore allows two or more computers running different operating systems and programs written in different languages to share processing. For example, a Java application could talk with a Perl program, which in turn talks with Python application that talks with ASP, and so on. System integrators often build custom connections between different systems, creating their own formats and protocols to make communications possible, but one can often end up with a large number of poorly documented single-use protocols. The RPC approach spares programmers the trouble of having to learn about underlying protocols, networking, and various implementation details.
 
18
 
 
19
.. i18n: XML-RPC can be used with Python, Java, Perl, PHP, C, C++, Ruby, Microsoft’s .NET and many other programming languages. Implementations are widely available for platforms such as Unix, Linux, Windows and the Macintosh.
 
20
..
 
21
 
 
22
XML-RPC can be used with Python, Java, Perl, PHP, C, C++, Ruby, Microsoft’s .NET and many other programming languages. Implementations are widely available for platforms such as Unix, Linux, Windows and the Macintosh.
 
23
 
 
24
.. i18n: An XML-RPC call is conducted between two parties: the client (the calling process) and the server (the called process). A server is made available at a particular URL (such as http://example.org:8080/rpcserv/).
 
25
..
 
26
 
 
27
An XML-RPC call is conducted between two parties: the client (the calling process) and the server (the called process). A server is made available at a particular URL (such as http://example.org:8080/rpcserv/).
 
28
 
 
29
.. i18n: The above text just touches the surface of XML-RPC. I recommend O'Reilly's "Programming Web Service with XML-RPC" for further reading. One may also wish to review the following links:
 
30
..
 
31
 
 
32
The above text just touches the surface of XML-RPC. I recommend O'Reilly's "Programming Web Service with XML-RPC" for further reading. One may also wish to review the following links:
 
33
 
 
34
.. i18n: Interfaces
 
35
.. i18n: ----------
 
36
..
 
37
 
 
38
Interfaces
 
39
----------
 
40
 
 
41
.. i18n: XML-RPC
 
42
.. i18n: +++++++
 
43
..
 
44
 
 
45
XML-RPC
 
46
+++++++
 
47
 
 
48
.. i18n: XML-RPC Architecture
 
49
.. i18n: """"""""""""""""""""
 
50
..
 
51
 
 
52
XML-RPC Architecture
 
53
""""""""""""""""""""
 
54
 
 
55
.. i18n: OpenERP is a based on a client/server architecture. The server and the client(s) communicate using the XML-RPC protocol. XML-RPC is a very simple protocol which allows the client to do remote procedure calls. The called function, its arguments, and the result of the call are transported using HTTP and encoded using XML. For more information on XML-RPC, please see: http://www.xml-rpc.com.
 
56
..
 
57
 
 
58
OpenERP is a based on a client/server architecture. The server and the client(s) communicate using the XML-RPC protocol. XML-RPC is a very simple protocol which allows the client to do remote procedure calls. The called function, its arguments, and the result of the call are transported using HTTP and encoded using XML. For more information on XML-RPC, please see: http://www.xml-rpc.com.
 
59
 
 
60
.. i18n: Architecture
 
61
.. i18n: """"""""""""
 
62
..
 
63
 
 
64
Architecture
 
65
""""""""""""
 
66
 
 
67
.. i18n: The diagram below synthesizes the client server architecture of OpenERP. OpenERP server and OpenERP clients communicate using XML-RPC.
 
68
..
 
69
 
 
70
The diagram below synthesizes the client server architecture of OpenERP. OpenERP server and OpenERP clients communicate using XML-RPC.
 
71
 
 
72
.. i18n: .. figure:: images/tech_arch.png
 
73
.. i18n:   :scale: 85
 
74
.. i18n:   :align: center
 
75
..
 
76
 
 
77
.. figure:: images/tech_arch.png
 
78
  :scale: 85
 
79
  :align: center
 
80
 
 
81
.. i18n: **Client**
 
82
..
 
83
 
 
84
**Client**
 
85
 
 
86
.. i18n: The logic of OpenERP is configured on the server side. The client is very simple; it is only used to post data (forms, lists, trees) and to send back the result to the server. The updates and the addition of new functionality don't need the clients to be frequently upgraded. This makes OpenERP easier to maintain.
 
87
..
 
88
 
 
89
The logic of OpenERP is configured on the server side. The client is very simple; it is only used to post data (forms, lists, trees) and to send back the result to the server. The updates and the addition of new functionality don't need the clients to be frequently upgraded. This makes OpenERP easier to maintain.
 
90
 
 
91
.. i18n: The client doesn't understand what it posts. Even actions like 'Click on the print icon' are sent to the server to ask how to react.
 
92
..
 
93
 
 
94
The client doesn't understand what it posts. Even actions like 'Click on the print icon' are sent to the server to ask how to react.
 
95
 
 
96
.. i18n: The client operation is very simple; when a user makes an action (save a form, open a menu, print, ...) it sends this action to the server. The server then sends the new action to execute to the client.
 
97
..
 
98
 
 
99
The client operation is very simple; when a user makes an action (save a form, open a menu, print, ...) it sends this action to the server. The server then sends the new action to execute to the client.
 
100
 
 
101
.. i18n: There are three types of action;
 
102
..
 
103
 
 
104
There are three types of action;
 
105
 
 
106
.. i18n:     * Open a window (form or tree)
 
107
.. i18n:     * Print a document
 
108
.. i18n:     * Execute a wizard
 
109
..
 
110
 
 
111
    * Open a window (form or tree)
 
112
    * Print a document
 
113
    * Execute a wizard
 
114
 
 
115
.. i18n: Python
 
116
.. i18n: ++++++
 
117
..
 
118
 
 
119
Python
 
120
++++++
 
121
 
 
122
.. i18n: Access tiny-server using xml-rpc
 
123
.. i18n: """"""""""""""""""""""""""""""""
 
124
..
 
125
 
 
126
Access tiny-server using xml-rpc
 
127
""""""""""""""""""""""""""""""""
 
128
 
 
129
.. i18n: Demo script
 
130
.. i18n: ~~~~~~~~~~~
 
131
..
 
132
 
 
133
Demo script
 
134
~~~~~~~~~~~
 
135
 
 
136
.. i18n:     * **Create a partner and his address**
 
137
..
 
138
 
 
139
    * **Create a partner and his address**
 
140
 
 
141
.. i18n:   ::
 
142
.. i18n: 
 
143
.. i18n:     import xmlrpclib
 
144
.. i18n: 
 
145
.. i18n:     username = 'admin' #the user
 
146
.. i18n:     pwd = 'admin'      #the password of the user
 
147
.. i18n:     dbname = 'terp'    #the database
 
148
.. i18n: 
 
149
.. i18n:     # Get the uid
 
150
.. i18n:     sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
 
151
.. i18n:     uid = sock_common.login(dbname, username, pwd)
 
152
.. i18n: 
 
153
.. i18n:     #replace localhost with the address of the server
 
154
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
 
155
.. i18n: 
 
156
.. i18n:     partner = {
 
157
.. i18n:        'name': 'Fabien Pinckaers',
 
158
.. i18n:        'lang': 'fr_FR',
 
159
.. i18n:     }
 
160
.. i18n: 
 
161
.. i18n:     partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
 
162
.. i18n: 
 
163
.. i18n:     address = {
 
164
.. i18n:        'partner_id': partner_id,
 
165
.. i18n:        'type' : 'default',
 
166
.. i18n:        'street': 'Chaussée de Namur 40',
 
167
.. i18n:        'zip': '1367',
 
168
.. i18n:        'city': 'Grand-Rosière',
 
169
.. i18n:        'phone': '+3281813700',
 
170
.. i18n:        'fax': '+3281733501',
 
171
.. i18n:     }
 
172
.. i18n: 
 
173
.. i18n:     address_id = sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
 
174
..
 
175
 
 
176
  ::
 
177
 
 
178
    import xmlrpclib
 
179
 
 
180
    username = 'admin' #the user
 
181
    pwd = 'admin'      #the password of the user
 
182
    dbname = 'terp'    #the database
 
183
 
 
184
    # Get the uid
 
185
    sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
 
186
    uid = sock_common.login(dbname, username, pwd)
 
187
 
 
188
    #replace localhost with the address of the server
 
189
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
 
190
 
 
191
    partner = {
 
192
       'name': 'Fabien Pinckaers',
 
193
       'lang': 'fr_FR',
 
194
    }
 
195
 
 
196
    partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
 
197
 
 
198
    address = {
 
199
       'partner_id': partner_id,
 
200
       'type' : 'default',
 
201
       'street': 'Chaussée de Namur 40',
 
202
       'zip': '1367',
 
203
       'city': 'Grand-Rosière',
 
204
       'phone': '+3281813700',
 
205
       'fax': '+3281733501',
 
206
    }
 
207
 
 
208
    address_id = sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
 
209
 
 
210
.. i18n: * **Search a partner**
 
211
.. i18n:   ::
 
212
.. i18n: 
 
213
.. i18n:     args = [('vat', '=', 'ZZZZZZ')] #query clause
 
214
.. i18n:     ids = sock.execute(dbname, uid, pwd, 'res.partner', 'search', args)
 
215
.. i18n: 
 
216
.. i18n: * **Read partner data**
 
217
.. i18n:   ::
 
218
.. i18n: 
 
219
.. i18n:     fields = ['name', 'active', 'vat', 'ref'] #fields to read
 
220
.. i18n:     data = sock.execute(dbname, uid, pwd, 'res.partner', 'read', ids, fields) #ids is a list of id
 
221
.. i18n: 
 
222
.. i18n: * **Update partner data**
 
223
.. i18n:   ::
 
224
.. i18n: 
 
225
.. i18n:     values = {'vat': 'ZZ1ZZZ'} #data to update
 
226
.. i18n:     result = sock.execute(dbname, uid, pwd, 'res.partner', 'write', ids, values)
 
227
.. i18n: 
 
228
.. i18n: * **Delete partner**
 
229
.. i18n:   ::
 
230
.. i18n: 
 
231
.. i18n:     # ids : list of id
 
232
.. i18n:     result = sock.execute(dbname, uid, pwd, 'res.partner', 'unlink', ids)
 
233
..
 
234
 
 
235
* **Search a partner**
 
236
  ::
 
237
 
 
238
    args = [('vat', '=', 'ZZZZZZ')] #query clause
 
239
    ids = sock.execute(dbname, uid, pwd, 'res.partner', 'search', args)
 
240
 
 
241
* **Read partner data**
 
242
  ::
 
243
 
 
244
    fields = ['name', 'active', 'vat', 'ref'] #fields to read
 
245
    data = sock.execute(dbname, uid, pwd, 'res.partner', 'read', ids, fields) #ids is a list of id
 
246
 
 
247
* **Update partner data**
 
248
  ::
 
249
 
 
250
    values = {'vat': 'ZZ1ZZZ'} #data to update
 
251
    result = sock.execute(dbname, uid, pwd, 'res.partner', 'write', ids, values)
 
252
 
 
253
* **Delete partner**
 
254
  ::
 
255
 
 
256
    # ids : list of id
 
257
    result = sock.execute(dbname, uid, pwd, 'res.partner', 'unlink', ids)
 
258
 
 
259
.. i18n: PHP
 
260
.. i18n: +++
 
261
..
 
262
 
 
263
PHP
 
264
+++
 
265
 
 
266
.. i18n: Access Open-server using xml-rpc
 
267
.. i18n: """"""""""""""""""""""""""""""""
 
268
..
 
269
 
 
270
Access Open-server using xml-rpc
 
271
""""""""""""""""""""""""""""""""
 
272
 
 
273
.. i18n: **Download the XML-RPC framework for PHP**
 
274
..
 
275
 
 
276
**Download the XML-RPC framework for PHP**
 
277
 
 
278
.. i18n: windows / linux: download the xml-rpc framework for php from http://phpxmlrpc.sourceforge.net/ The latest stable release is version 2.2 released on February 25, 2007
 
279
..
 
280
 
 
281
windows / linux: download the xml-rpc framework for php from http://phpxmlrpc.sourceforge.net/ The latest stable release is version 2.2 released on February 25, 2007
 
282
 
 
283
.. i18n: **Setup the XML-RPC for PHP**
 
284
..
 
285
 
 
286
**Setup the XML-RPC for PHP**
 
287
 
 
288
.. i18n: extract file xmlrpc-2.2.tar.gz and take the file xmlrpc.inc from lib directory place the xmlrpc.inc in the php library folder restart the apcahe/iis server
 
289
..
 
290
 
 
291
extract file xmlrpc-2.2.tar.gz and take the file xmlrpc.inc from lib directory place the xmlrpc.inc in the php library folder restart the apcahe/iis server
 
292
 
 
293
.. i18n: **Demo script**
 
294
..
 
295
 
 
296
**Demo script**
 
297
 
 
298
.. i18n: * **Login**
 
299
..
 
300
 
 
301
* **Login**
 
302
 
 
303
.. i18n: .. code-block:: php
 
304
.. i18n: 
 
305
.. i18n:     function connect() {
 
306
.. i18n:        var $user = 'admin';
 
307
.. i18n:        var $password = 'admin';
 
308
.. i18n:        var $dbname = 'db_name';
 
309
.. i18n:        var $server_url = 'http://localhost:8069/xmlrpc/';
 
310
.. i18n: 
 
311
.. i18n:        if(isset($_COOKIE["user_id"]) == true)  {
 
312
.. i18n:            if($_COOKIE["user_id"]>0) {
 
313
.. i18n:            return $_COOKIE["user_id"];
 
314
.. i18n:            }
 
315
.. i18n:        }
 
316
.. i18n: 
 
317
.. i18n:        $sock = new xmlrpc_client($server_url.'common');
 
318
.. i18n:        $msg = new xmlrpcmsg('login');
 
319
.. i18n:        $msg->addParam(new xmlrpcval($dbname, "string"));
 
320
.. i18n:        $msg->addParam(new xmlrpcval($user, "string"));
 
321
.. i18n:        $msg->addParam(new xmlrpcval($password, "string"));
 
322
.. i18n:        $resp =  $sock->send($msg);
 
323
.. i18n:        $val = $resp->value();
 
324
.. i18n:        $id = $val->scalarval();
 
325
.. i18n:        setcookie("user_id",$id,time()+3600);
 
326
.. i18n:        if($id > 0) {
 
327
.. i18n:            return $id;
 
328
.. i18n:        }else{
 
329
.. i18n:            return -1;
 
330
.. i18n:        }
 
331
.. i18n:      }
 
332
..
 
333
 
 
334
.. code-block:: php
 
335
 
 
336
    function connect() {
 
337
       var $user = 'admin';
 
338
       var $password = 'admin';
 
339
       var $dbname = 'db_name';
 
340
       var $server_url = 'http://localhost:8069/xmlrpc/';
 
341
 
 
342
       if(isset($_COOKIE["user_id"]) == true)  {
 
343
           if($_COOKIE["user_id"]>0) {
 
344
           return $_COOKIE["user_id"];
 
345
           }
 
346
       }
 
347
 
 
348
       $sock = new xmlrpc_client($server_url.'common');
 
349
       $msg = new xmlrpcmsg('login');
 
350
       $msg->addParam(new xmlrpcval($dbname, "string"));
 
351
       $msg->addParam(new xmlrpcval($user, "string"));
 
352
       $msg->addParam(new xmlrpcval($password, "string"));
 
353
       $resp =  $sock->send($msg);
 
354
       $val = $resp->value();
 
355
       $id = $val->scalarval();
 
356
       setcookie("user_id",$id,time()+3600);
 
357
       if($id > 0) {
 
358
           return $id;
 
359
       }else{
 
360
           return -1;
 
361
       }
 
362
     }
 
363
 
 
364
.. i18n: * **Search**
 
365
..
 
366
 
 
367
* **Search**
 
368
 
 
369
.. i18n: .. code-block:: php
 
370
.. i18n: 
 
371
.. i18n:     /**
 
372
.. i18n:      * $client = xml-rpc handler
 
373
.. i18n:      * $relation = name of the relation ex: res.partner
 
374
.. i18n:      * $attribute = name of the attribute ex:code
 
375
.. i18n:      * $operator = search term operator ex: ilike, =, !=
 
376
.. i18n:      * $key=search for
 
377
.. i18n:      */
 
378
.. i18n: 
 
379
.. i18n:     function search($client,$relation,$attribute,$operator,$keys) {
 
380
.. i18n:          var $user = 'admin';
 
381
.. i18n:          var $password = 'admin';
 
382
.. i18n:          var $userId = -1;
 
383
.. i18n:          var $dbname = 'db_name';
 
384
.. i18n:          var $server_url = 'http://localhost:8069/xmlrpc/';
 
385
.. i18n: 
 
386
.. i18n:          $key = array(new xmlrpcval(array(new xmlrpcval($attribute , "string"),
 
387
.. i18n:                   new xmlrpcval($operator,"string"),
 
388
.. i18n:                   new xmlrpcval($keys,"string")),"array"),
 
389
.. i18n:             );
 
390
.. i18n: 
 
391
.. i18n:          if($userId<=0) {
 
392
.. i18n:          connect();
 
393
.. i18n:          }
 
394
.. i18n: 
 
395
.. i18n:          $msg = new xmlrpcmsg('execute');
 
396
.. i18n:          $msg->addParam(new xmlrpcval($dbname, "string"));
 
397
.. i18n:          $msg->addParam(new xmlrpcval($userId, "int"));
 
398
.. i18n:          $msg->addParam(new xmlrpcval($password, "string"));
 
399
.. i18n:          $msg->addParam(new xmlrpcval($relation, "string"));
 
400
.. i18n:          $msg->addParam(new xmlrpcval("search", "string"));
 
401
.. i18n:          $msg->addParam(new xmlrpcval($key, "array"));
 
402
.. i18n: 
 
403
.. i18n:          $resp = $client->send($msg);
 
404
.. i18n:          $val = $resp->value();
 
405
.. i18n:          $ids = $val->scalarval();
 
406
.. i18n: 
 
407
.. i18n:          return $ids;
 
408
.. i18n:     }
 
409
..
 
410
 
 
411
.. code-block:: php
 
412
 
 
413
    /**
 
414
     * $client = xml-rpc handler
 
415
     * $relation = name of the relation ex: res.partner
 
416
     * $attribute = name of the attribute ex:code
 
417
     * $operator = search term operator ex: ilike, =, !=
 
418
     * $key=search for
 
419
     */
 
420
 
 
421
    function search($client,$relation,$attribute,$operator,$keys) {
 
422
         var $user = 'admin';
 
423
         var $password = 'admin';
 
424
         var $userId = -1;
 
425
         var $dbname = 'db_name';
 
426
         var $server_url = 'http://localhost:8069/xmlrpc/';
 
427
 
 
428
         $key = array(new xmlrpcval(array(new xmlrpcval($attribute , "string"),
 
429
                  new xmlrpcval($operator,"string"),
 
430
                  new xmlrpcval($keys,"string")),"array"),
 
431
            );
 
432
 
 
433
         if($userId<=0) {
 
434
         connect();
 
435
         }
 
436
 
 
437
         $msg = new xmlrpcmsg('execute');
 
438
         $msg->addParam(new xmlrpcval($dbname, "string"));
 
439
         $msg->addParam(new xmlrpcval($userId, "int"));
 
440
         $msg->addParam(new xmlrpcval($password, "string"));
 
441
         $msg->addParam(new xmlrpcval($relation, "string"));
 
442
         $msg->addParam(new xmlrpcval("search", "string"));
 
443
         $msg->addParam(new xmlrpcval($key, "array"));
 
444
 
 
445
         $resp = $client->send($msg);
 
446
         $val = $resp->value();
 
447
         $ids = $val->scalarval();
 
448
 
 
449
         return $ids;
 
450
    }
 
451
 
 
452
.. i18n: * **Create**
 
453
..
 
454
 
 
455
* **Create**
 
456
 
 
457
.. i18n: .. code-block:: php
 
458
.. i18n: 
 
459
.. i18n:         <?
 
460
.. i18n: 
 
461
.. i18n:         include('xmlrpc.inc');
 
462
.. i18n: 
 
463
.. i18n:         $arrayVal = array(
 
464
.. i18n:         'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
 
465
.. i18n:         'vat'=>new xmlrpcval('BE477472701' , "string")
 
466
.. i18n:         );
 
467
.. i18n: 
 
468
.. i18n:         $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
 
469
.. i18n: 
 
470
.. i18n:         $msg = new xmlrpcmsg('execute');
 
471
.. i18n:         $msg->addParam(new xmlrpcval("dbname", "string"));
 
472
.. i18n:         $msg->addParam(new xmlrpcval("3", "int"));
 
473
.. i18n:         $msg->addParam(new xmlrpcval("demo", "string"));
 
474
.. i18n:         $msg->addParam(new xmlrpcval("res.partner", "string"));
 
475
.. i18n:         $msg->addParam(new xmlrpcval("create", "string"));
 
476
.. i18n:         $msg->addParam(new xmlrpcval($arrayVal, "struct"));
 
477
.. i18n: 
 
478
.. i18n:         $resp = $client->send($msg);
 
479
.. i18n: 
 
480
.. i18n:         if ($resp->faultCode())
 
481
.. i18n: 
 
482
.. i18n:             echo 'Error: '.$resp->faultString();
 
483
.. i18n: 
 
484
.. i18n:         else
 
485
.. i18n: 
 
486
.. i18n:             echo 'Partner '.$resp->value()->scalarval().' created !';
 
487
.. i18n: 
 
488
.. i18n:         ?>
 
489
..
 
490
 
 
491
.. code-block:: php
 
492
 
 
493
        <?
 
494
 
 
495
        include('xmlrpc.inc');
 
496
 
 
497
        $arrayVal = array(
 
498
        'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
 
499
        'vat'=>new xmlrpcval('BE477472701' , "string")
 
500
        );
 
501
 
 
502
        $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
 
503
 
 
504
        $msg = new xmlrpcmsg('execute');
 
505
        $msg->addParam(new xmlrpcval("dbname", "string"));
 
506
        $msg->addParam(new xmlrpcval("3", "int"));
 
507
        $msg->addParam(new xmlrpcval("demo", "string"));
 
508
        $msg->addParam(new xmlrpcval("res.partner", "string"));
 
509
        $msg->addParam(new xmlrpcval("create", "string"));
 
510
        $msg->addParam(new xmlrpcval($arrayVal, "struct"));
 
511
 
 
512
        $resp = $client->send($msg);
 
513
 
 
514
        if ($resp->faultCode())
 
515
 
 
516
            echo 'Error: '.$resp->faultString();
 
517
 
 
518
        else
 
519
 
 
520
            echo 'Partner '.$resp->value()->scalarval().' created !';
 
521
 
 
522
        ?>
 
523
 
 
524
.. i18n: * **Write**
 
525
..
 
526
 
 
527
* **Write**
 
528
 
 
529
.. i18n: .. code-block:: php
 
530
.. i18n: 
 
531
.. i18n:     /**
 
532
.. i18n:      * $client = xml-rpc handler
 
533
.. i18n:      * $relation = name of the relation ex: res.partner
 
534
.. i18n:      * $attribute = name of the attribute ex:code
 
535
.. i18n:      * $operator = search term operator ex: ilike, =, !=
 
536
.. i18n:      * $id = id of the record to be updated
 
537
.. i18n:      * $data = data to be updated
 
538
.. i18n:      */
 
539
.. i18n: 
 
540
.. i18n:     function write($client,$relation,$attribute,$operator,$data,$id) {
 
541
.. i18n:          var $user = 'admin';
 
542
.. i18n:          var $password = 'admin';
 
543
.. i18n:          var $userId = -1;
 
544
.. i18n:          var $dbname = 'db_name';
 
545
.. i18n:          var $server_url = 'http://localhost:8069/xmlrpc/';
 
546
.. i18n: 
 
547
.. i18n:          $id_val = array();
 
548
.. i18n:         $id_val[0] = new xmlrpcval($id, "int");
 
549
.. i18n: 
 
550
.. i18n:          if($userId<=0) {
 
551
.. i18n:          connect();
 
552
.. i18n:          }
 
553
.. i18n: 
 
554
.. i18n:          $msg = new xmlrpcmsg('execute');
 
555
.. i18n:          $msg->addParam(new xmlrpcval($dbname, "string"));
 
556
.. i18n:          $msg->addParam(new xmlrpcval($userId, "int"));
 
557
.. i18n:          $msg->addParam(new xmlrpcval($password, "string"));
 
558
.. i18n:          $msg->addParam(new xmlrpcval($relation, "string"));
 
559
.. i18n:          $msg->addParam(new xmlrpcval("write", "string"));
 
560
.. i18n:          $msg->addParam(new xmlrpcval($id, "array"));
 
561
.. i18n:          $msg->addParam(new xmlrpcval($data, "struct"));
 
562
.. i18n: 
 
563
.. i18n:          $resp = $client->send($msg);
 
564
.. i18n:          $val = $resp->value();
 
565
.. i18n:          $record = $val->scalarval();
 
566
.. i18n: 
 
567
.. i18n:          return $record;
 
568
.. i18n: 
 
569
.. i18n:     }
 
570
..
 
571
 
 
572
.. code-block:: php
 
573
 
 
574
    /**
 
575
     * $client = xml-rpc handler
 
576
     * $relation = name of the relation ex: res.partner
 
577
     * $attribute = name of the attribute ex:code
 
578
     * $operator = search term operator ex: ilike, =, !=
 
579
     * $id = id of the record to be updated
 
580
     * $data = data to be updated
 
581
     */
 
582
 
 
583
    function write($client,$relation,$attribute,$operator,$data,$id) {
 
584
         var $user = 'admin';
 
585
         var $password = 'admin';
 
586
         var $userId = -1;
 
587
         var $dbname = 'db_name';
 
588
         var $server_url = 'http://localhost:8069/xmlrpc/';
 
589
 
 
590
         $id_val = array();
 
591
         $id_val[0] = new xmlrpcval($id, "int");
 
592
 
 
593
         if($userId<=0) {
 
594
         connect();
 
595
         }
 
596
 
 
597
         $msg = new xmlrpcmsg('execute');
 
598
         $msg->addParam(new xmlrpcval($dbname, "string"));
 
599
         $msg->addParam(new xmlrpcval($userId, "int"));
 
600
         $msg->addParam(new xmlrpcval($password, "string"));
 
601
         $msg->addParam(new xmlrpcval($relation, "string"));
 
602
         $msg->addParam(new xmlrpcval("write", "string"));
 
603
         $msg->addParam(new xmlrpcval($id, "array"));
 
604
         $msg->addParam(new xmlrpcval($data, "struct"));
 
605
 
 
606
         $resp = $client->send($msg);
 
607
         $val = $resp->value();
 
608
         $record = $val->scalarval();
 
609
 
 
610
         return $record;
 
611
 
 
612
    }
 
613
 
 
614
.. i18n: JAVA
 
615
.. i18n: ++++
 
616
..
 
617
 
 
618
JAVA
 
619
++++
 
620
 
 
621
.. i18n: Access Open-server using xml-rpc
 
622
.. i18n: """"""""""""""""""""""""""""""""
 
623
..
 
624
 
 
625
Access Open-server using xml-rpc
 
626
""""""""""""""""""""""""""""""""
 
627
 
 
628
.. i18n: **Download the apache XML-RPC framework for JAVA**
 
629
..
 
630
 
 
631
**Download the apache XML-RPC framework for JAVA**
 
632
 
 
633
.. i18n: Download the xml-rpc framework for java from http://ws.apache.org/xmlrpc/ The latest stable release is version 3.1 released on August 12, 2007.
 
634
.. i18n: All OpenERP errors throw exceptions because the framework allows only an int as the error code where OpenERP returns a string.
 
635
..
 
636
 
 
637
Download the xml-rpc framework for java from http://ws.apache.org/xmlrpc/ The latest stable release is version 3.1 released on August 12, 2007.
 
638
All OpenERP errors throw exceptions because the framework allows only an int as the error code where OpenERP returns a string.
 
639
 
 
640
.. i18n: **Demo script**
 
641
..
 
642
 
 
643
**Demo script**
 
644
 
 
645
.. i18n: * **Find Databases**
 
646
..
 
647
 
 
648
* **Find Databases**
 
649
 
 
650
.. i18n: .. code-block:: java
 
651
.. i18n: 
 
652
.. i18n:     import java.net.URL;
 
653
.. i18n:     import java.util.Vector;
 
654
.. i18n: 
 
655
.. i18n:     import org.apache.commons.lang.StringUtils;
 
656
.. i18n:     import org.apache.xmlrpc.XmlRpcException;
 
657
.. i18n:     import org.apache.xmlrpc.client.XmlRpcClient;
 
658
.. i18n:     import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 
659
.. i18n: 
 
660
.. i18n:     public Vector<String> getDatabaseList(String host, int port)
 
661
.. i18n:     {
 
662
.. i18n:       XmlRpcClient xmlrpcDb = new XmlRpcClient();
 
663
.. i18n: 
 
664
.. i18n:       XmlRpcClientConfigImpl xmlrpcConfigDb = new XmlRpcClientConfigImpl();
 
665
.. i18n:       xmlrpcConfigDb.setEnabledForExtensions(true);
 
666
.. i18n:       xmlrpcConfigDb.setServerURL(new URL("http",host,port,"/xmlrpc/db"));
 
667
.. i18n: 
 
668
.. i18n:       xmlrpcDb.setConfig(xmlrpcConfigDb);
 
669
.. i18n: 
 
670
.. i18n:       try {
 
671
.. i18n:         //Retrieve databases
 
672
.. i18n:         Vector<Object> params = new Vector<Object>();
 
673
.. i18n:         Object result = xmlrpcDb.execute("list", params);
 
674
.. i18n:         Object[] a = (Object[]) result;
 
675
.. i18n: 
 
676
.. i18n:         Vector<String> res = new Vector<String>();
 
677
.. i18n:         for (int i = 0; i < a.length; i++) {
 
678
.. i18n:         if (a[i] instanceof String)
 
679
.. i18n:         {
 
680
.. i18n:           res.addElement((String)a[i]);
 
681
.. i18n:         }
 
682
.. i18n:       }
 
683
.. i18n:       catch (XmlRpcException e) {
 
684
.. i18n:         logger.warn("XmlException Error while retrieving OpenERP Databases: ",e);
 
685
.. i18n:         return -2;
 
686
.. i18n:       }
 
687
.. i18n:       catch (Exception e)
 
688
.. i18n:       {
 
689
.. i18n:         logger.warn("Error while retrieving OpenERP Databases: ",e);
 
690
.. i18n:         return -3;
 
691
.. i18n:       }
 
692
.. i18n:     }
 
693
..
 
694
 
 
695
.. code-block:: java
 
696
 
 
697
    import java.net.URL;
 
698
    import java.util.Vector;
 
699
 
 
700
    import org.apache.commons.lang.StringUtils;
 
701
    import org.apache.xmlrpc.XmlRpcException;
 
702
    import org.apache.xmlrpc.client.XmlRpcClient;
 
703
    import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 
704
 
 
705
    public Vector<String> getDatabaseList(String host, int port)
 
706
    {
 
707
      XmlRpcClient xmlrpcDb = new XmlRpcClient();
 
708
 
 
709
      XmlRpcClientConfigImpl xmlrpcConfigDb = new XmlRpcClientConfigImpl();
 
710
      xmlrpcConfigDb.setEnabledForExtensions(true);
 
711
      xmlrpcConfigDb.setServerURL(new URL("http",host,port,"/xmlrpc/db"));
 
712
 
 
713
      xmlrpcDb.setConfig(xmlrpcConfigDb);
 
714
 
 
715
      try {
 
716
        //Retrieve databases
 
717
        Vector<Object> params = new Vector<Object>();
 
718
        Object result = xmlrpcDb.execute("list", params);
 
719
        Object[] a = (Object[]) result;
 
720
 
 
721
        Vector<String> res = new Vector<String>();
 
722
        for (int i = 0; i < a.length; i++) {
 
723
        if (a[i] instanceof String)
 
724
        {
 
725
          res.addElement((String)a[i]);
 
726
        }
 
727
      }
 
728
      catch (XmlRpcException e) {
 
729
        logger.warn("XmlException Error while retrieving OpenERP Databases: ",e);
 
730
        return -2;
 
731
      }
 
732
      catch (Exception e)
 
733
      {
 
734
        logger.warn("Error while retrieving OpenERP Databases: ",e);
 
735
        return -3;
 
736
      }
 
737
    }
 
738
 
 
739
.. i18n: * **Login**
 
740
..
 
741
 
 
742
* **Login**
 
743
 
 
744
.. i18n: .. code-block:: java
 
745
.. i18n: 
 
746
.. i18n:     import java.net.URL;
 
747
.. i18n: 
 
748
.. i18n:     import org.apache.commons.lang.StringUtils;
 
749
.. i18n:     import org.apache.xmlrpc.XmlRpcException;
 
750
.. i18n:     import org.apache.xmlrpc.client.XmlRpcClient;
 
751
.. i18n:     import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 
752
.. i18n: 
 
753
.. i18n:     public int Connect(String host, int port, String tinydb, String login, String password)
 
754
.. i18n:     {
 
755
.. i18n:       XmlRpcClient xmlrpcLogin = new XmlRpcClient();
 
756
.. i18n: 
 
757
.. i18n:       XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl();
 
758
.. i18n:       xmlrpcConfigLogin.setEnabledForExtensions(true);
 
759
.. i18n:       xmlrpcConfigLogin.setServerURL(new URL("http",host,port,"/xmlrpc/common"));
 
760
.. i18n: 
 
761
.. i18n:       xmlrpcLogin.setConfig(xmlrpcConfigLogin);
 
762
.. i18n: 
 
763
.. i18n:       try {
 
764
.. i18n:         //Connect
 
765
.. i18n:         params = new Object[] {tinydb,login,password};
 
766
.. i18n:         Object id = xmlrpcLogin.execute("login", params);
 
767
.. i18n:         if (id instanceof Integer)
 
768
.. i18n:           return (Integer)id;
 
769
.. i18n:         return -1;
 
770
.. i18n:       }
 
771
.. i18n:       catch (XmlRpcException e) {
 
772
.. i18n:         logger.warn("XmlException Error while logging to OpenERP: ",e);
 
773
.. i18n:         return -2;
 
774
.. i18n:       }
 
775
.. i18n:       catch (Exception e)
 
776
.. i18n:       {
 
777
.. i18n:         logger.warn("Error while logging to OpenERP: ",e);
 
778
.. i18n:         return -3;
 
779
.. i18n:       }
 
780
.. i18n:     }
 
781
..
 
782
 
 
783
.. code-block:: java
 
784
 
 
785
    import java.net.URL;
 
786
 
 
787
    import org.apache.commons.lang.StringUtils;
 
788
    import org.apache.xmlrpc.XmlRpcException;
 
789
    import org.apache.xmlrpc.client.XmlRpcClient;
 
790
    import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 
791
 
 
792
    public int Connect(String host, int port, String tinydb, String login, String password)
 
793
    {
 
794
      XmlRpcClient xmlrpcLogin = new XmlRpcClient();
 
795
 
 
796
      XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl();
 
797
      xmlrpcConfigLogin.setEnabledForExtensions(true);
 
798
      xmlrpcConfigLogin.setServerURL(new URL("http",host,port,"/xmlrpc/common"));
 
799
 
 
800
      xmlrpcLogin.setConfig(xmlrpcConfigLogin);
 
801
 
 
802
      try {
 
803
        //Connect
 
804
        params = new Object[] {tinydb,login,password};
 
805
        Object id = xmlrpcLogin.execute("login", params);
 
806
        if (id instanceof Integer)
 
807
          return (Integer)id;
 
808
        return -1;
 
809
      }
 
810
      catch (XmlRpcException e) {
 
811
        logger.warn("XmlException Error while logging to OpenERP: ",e);
 
812
        return -2;
 
813
      }
 
814
      catch (Exception e)
 
815
      {
 
816
        logger.warn("Error while logging to OpenERP: ",e);
 
817
        return -3;
 
818
      }
 
819
    }
 
820
 
 
821
.. i18n: * **Search**
 
822
.. i18n:   ::
 
823
.. i18n: 
 
824
.. i18n:     TODO
 
825
.. i18n: 
 
826
.. i18n: * **Create**
 
827
.. i18n:   ::
 
828
.. i18n: 
 
829
.. i18n:     TODO
 
830
.. i18n: 
 
831
.. i18n: * **Write**
 
832
.. i18n:   ::
 
833
.. i18n: 
 
834
.. i18n:     TODO
 
835
..
 
836
 
 
837
* **Search**
 
838
  ::
 
839
 
 
840
    TODO
 
841
 
 
842
* **Create**
 
843
  ::
 
844
 
 
845
    TODO
 
846
 
 
847
* **Write**
 
848
  ::
 
849
 
 
850
    TODO
 
851
 
 
852
.. i18n: Python Example
 
853
.. i18n: --------------
 
854
..
 
855
 
 
856
Python Example
 
857
--------------
 
858
 
 
859
.. i18n: Example of creation of a partner and his address.
 
860
..
 
861
 
 
862
Example of creation of a partner and his address.
 
863
 
 
864
.. i18n: .. code-block:: python
 
865
.. i18n: 
 
866
.. i18n:     import xmlrpclib
 
867
.. i18n: 
 
868
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
 
869
.. i18n:     uid = 1
 
870
.. i18n:     pwd = 'demo'
 
871
.. i18n: 
 
872
.. i18n:     partner = {
 
873
.. i18n:         'title': 'Monsieur',
 
874
.. i18n:         'name': 'Fabien Pinckaers',
 
875
.. i18n:         'lang': 'fr',
 
876
.. i18n:         'active': True,
 
877
.. i18n:     }
 
878
.. i18n: 
 
879
.. i18n:     partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
 
880
.. i18n: 
 
881
.. i18n:     address = {
 
882
.. i18n:         'partner_id': partner_id,
 
883
.. i18n:         'type': 'default',
 
884
.. i18n:         'street': 'Rue du vieux chateau, 21',
 
885
.. i18n:         'zip': '1457',
 
886
.. i18n:         'city': 'Walhain',
 
887
.. i18n:         'phone': '(+32)10.68.94.39',
 
888
.. i18n:         'fax': '(+32)10.68.94.39',
 
889
.. i18n:     }
 
890
.. i18n: 
 
891
.. i18n:     sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
 
892
..
 
893
 
 
894
.. code-block:: python
 
895
 
 
896
    import xmlrpclib
 
897
 
 
898
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
 
899
    uid = 1
 
900
    pwd = 'demo'
 
901
 
 
902
    partner = {
 
903
        'title': 'Monsieur',
 
904
        'name': 'Fabien Pinckaers',
 
905
        'lang': 'fr',
 
906
        'active': True,
 
907
    }
 
908
 
 
909
    partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
 
910
 
 
911
    address = {
 
912
        'partner_id': partner_id,
 
913
        'type': 'default',
 
914
        'street': 'Rue du vieux chateau, 21',
 
915
        'zip': '1457',
 
916
        'city': 'Walhain',
 
917
        'phone': '(+32)10.68.94.39',
 
918
        'fax': '(+32)10.68.94.39',
 
919
    }
 
920
 
 
921
    sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
 
922
 
 
923
.. i18n: To get the UID of a user, you can use the following script:
 
924
..
 
925
 
 
926
To get the UID of a user, you can use the following script:
 
927
 
 
928
.. i18n: .. code-block:: python
 
929
.. i18n: 
 
930
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
 
931
.. i18n:      UID = sock.login('terp3', 'admin', 'admin')
 
932
..
 
933
 
 
934
.. code-block:: python
 
935
 
 
936
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
 
937
     UID = sock.login('terp3', 'admin', 'admin')
 
938
 
 
939
.. i18n: CRUD example:
 
940
..
 
941
 
 
942
CRUD example:
 
943
 
 
944
.. i18n: .. code-block:: python
 
945
.. i18n: 
 
946
.. i18n:     """
 
947
.. i18n:     :The login function is under
 
948
.. i18n:     ::    http://localhost:8069/xmlrpc/common
 
949
.. i18n:     :For object retrieval use:
 
950
.. i18n:     ::    http://localhost:8069/xmlrpc/object
 
951
.. i18n:     """
 
952
.. i18n:     import xmlrpclib
 
953
.. i18n: 
 
954
.. i18n:     user = 'admin'
 
955
.. i18n:     pwd = 'admin'
 
956
.. i18n:     dbname = 'terp3'
 
957
.. i18n:     model = 'res.partner'
 
958
.. i18n: 
 
959
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
 
960
.. i18n:     uid = sock.login(dbname ,user ,pwd)
 
961
.. i18n: 
 
962
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
 
963
.. i18n: 
 
964
.. i18n:     # CREATE A PARTNER
 
965
.. i18n:     partner_data = {'name'.. code-block:: php:'Tiny', 'active':True, 'vat':'ZZZZZ'}
 
966
.. i18n:     partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)
 
967
.. i18n: 
 
968
.. i18n:     # The relation between res.partner and res.partner.category is of type many2many
 
969
.. i18n:     # To add  categories to a partner use the following format:
 
970
.. i18n:     partner_data = {'name':'Provider2', 'category_id': [(6,0,[3, 2, 1])]}
 
971
.. i18n:     # Where [3, 2, 1] are id fields of lines in res.partner.category
 
972
.. i18n: 
 
973
.. i18n:     # SEARCH PARTNERS
 
974
.. i18n:     args = [('vat', '=', 'ZZZZZ'),]
 
975
.. i18n:     ids = sock.execute(dbname, uid, pwd, model, 'search', args)
 
976
.. i18n: 
 
977
.. i18n:     # READ PARTNER DATA
 
978
.. i18n:     fields = ['name', 'active', 'vat', 'ref']
 
979
.. i18n:     results = sock.execute(dbname, uid, pwd, model, 'read', ids, fields)
 
980
.. i18n:     print results
 
981
.. i18n: 
 
982
.. i18n:     # EDIT PARTNER DATA
 
983
.. i18n:     values = {'vat':'ZZ1ZZ'}
 
984
.. i18n:     results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
 
985
.. i18n: 
 
986
.. i18n:     # DELETE PARTNER DATA
 
987
.. i18n:     results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
 
988
..
 
989
 
 
990
.. code-block:: python
 
991
 
 
992
    """
 
993
    :The login function is under
 
994
    ::    http://localhost:8069/xmlrpc/common
 
995
    :For object retrieval use:
 
996
    ::    http://localhost:8069/xmlrpc/object
 
997
    """
 
998
    import xmlrpclib
 
999
 
 
1000
    user = 'admin'
 
1001
    pwd = 'admin'
 
1002
    dbname = 'terp3'
 
1003
    model = 'res.partner'
 
1004
 
 
1005
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
 
1006
    uid = sock.login(dbname ,user ,pwd)
 
1007
 
 
1008
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
 
1009
 
 
1010
    # CREATE A PARTNER
 
1011
    partner_data = {'name'.. code-block:: php:'Tiny', 'active':True, 'vat':'ZZZZZ'}
 
1012
    partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)
 
1013
 
 
1014
    # The relation between res.partner and res.partner.category is of type many2many
 
1015
    # To add  categories to a partner use the following format:
 
1016
    partner_data = {'name':'Provider2', 'category_id': [(6,0,[3, 2, 1])]}
 
1017
    # Where [3, 2, 1] are id fields of lines in res.partner.category
 
1018
 
 
1019
    # SEARCH PARTNERS
 
1020
    args = [('vat', '=', 'ZZZZZ'),]
 
1021
    ids = sock.execute(dbname, uid, pwd, model, 'search', args)
 
1022
 
 
1023
    # READ PARTNER DATA
 
1024
    fields = ['name', 'active', 'vat', 'ref']
 
1025
    results = sock.execute(dbname, uid, pwd, model, 'read', ids, fields)
 
1026
    print results
 
1027
 
 
1028
    # EDIT PARTNER DATA
 
1029
    values = {'vat':'ZZ1ZZ'}
 
1030
    results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
 
1031
 
 
1032
    # DELETE PARTNER DATA
 
1033
    results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
 
1034
 
 
1035
.. i18n: PRINT example:
 
1036
..
 
1037
 
 
1038
PRINT example:
 
1039
 
 
1040
.. i18n:    1. PRINT INVOICE
 
1041
.. i18n:    2. IDS is the invoice ID, as returned by:
 
1042
.. i18n:    3. ids = sock.execute(dbname, uid, pwd, 'account.invoice', 'search', [('number', 'ilike', invoicenumber), ('type', '=', 'out_invoice')])
 
1043
..
 
1044
 
 
1045
   1. PRINT INVOICE
 
1046
   2. IDS is the invoice ID, as returned by:
 
1047
   3. ids = sock.execute(dbname, uid, pwd, 'account.invoice', 'search', [('number', 'ilike', invoicenumber), ('type', '=', 'out_invoice')])
 
1048
 
 
1049
.. i18n: .. code-block:: python
 
1050
.. i18n: 
 
1051
.. i18n:     import time
 
1052
.. i18n:     import base64
 
1053
.. i18n:     printsock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/report')
 
1054
.. i18n:     model = 'account.invoice'
 
1055
.. i18n:     id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'id': ids[0], 'report_type':'pdf'})
 
1056
.. i18n:     time.sleep(5)
 
1057
.. i18n:     state = False
 
1058
.. i18n:     attempt = 0
 
1059
.. i18n:     while not state:
 
1060
.. i18n:         report = printsock.report_get(dbname, uid, pwd, id_report)
 
1061
.. i18n:         state = report['state']
 
1062
.. i18n:         if not state:
 
1063
.. i18n:         time.sleep(1)
 
1064
.. i18n:         attempt += 1
 
1065
.. i18n:         if attempt>200:
 
1066
.. i18n:         print 'Printing aborted, too long delay !'
 
1067
.. i18n: 
 
1068
.. i18n:         string_pdf = base64.decodestring(report['result'])
 
1069
.. i18n:         file_pdf = open('/tmp/file.pdf','w')
 
1070
.. i18n:         file_pdf.write(string_pdf)
 
1071
.. i18n:         file_pdf.close()
 
1072
..
 
1073
 
 
1074
.. code-block:: python
 
1075
 
 
1076
    import time
 
1077
    import base64
 
1078
    printsock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/report')
 
1079
    model = 'account.invoice'
 
1080
    id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'id': ids[0], 'report_type':'pdf'})
 
1081
    time.sleep(5)
 
1082
    state = False
 
1083
    attempt = 0
 
1084
    while not state:
 
1085
        report = printsock.report_get(dbname, uid, pwd, id_report)
 
1086
        state = report['state']
 
1087
        if not state:
 
1088
        time.sleep(1)
 
1089
        attempt += 1
 
1090
        if attempt>200:
 
1091
        print 'Printing aborted, too long delay !'
 
1092
 
 
1093
        string_pdf = base64.decodestring(report['result'])
 
1094
        file_pdf = open('/tmp/file.pdf','w')
 
1095
        file_pdf.write(string_pdf)
 
1096
        file_pdf.close()
 
1097
 
 
1098
.. i18n: PHP Example
 
1099
.. i18n: -----------
 
1100
..
 
1101
 
 
1102
PHP Example
 
1103
-----------
 
1104
 
 
1105
.. i18n: Here is an example on how to insert a new partner using PHP. This example makes use the phpxmlrpc library, available on sourceforge.
 
1106
..
 
1107
 
 
1108
Here is an example on how to insert a new partner using PHP. This example makes use the phpxmlrpc library, available on sourceforge.
 
1109
 
 
1110
.. i18n: .. code-block:: php
 
1111
.. i18n: 
 
1112
.. i18n:     <?
 
1113
.. i18n: 
 
1114
.. i18n:         include('xmlrpc.inc');
 
1115
.. i18n: 
 
1116
.. i18n:         $arrayVal = array(
 
1117
.. i18n:         'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
 
1118
.. i18n:         'vat'=>new xmlrpcval('BE477472701' , "string")
 
1119
.. i18n:         );
 
1120
.. i18n: 
 
1121
.. i18n:         $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
 
1122
.. i18n: 
 
1123
.. i18n:         $msg = new xmlrpcmsg('execute');
 
1124
.. i18n:         $msg->addParam(new xmlrpcval("dbname", "string"));
 
1125
.. i18n:         $msg->addParam(new xmlrpcval("3", "int"));
 
1126
.. i18n:         $msg->addParam(new xmlrpcval("demo", "string"));
 
1127
.. i18n:         $msg->addParam(new xmlrpcval("res.partner", "string"));
 
1128
.. i18n:         $msg->addParam(new xmlrpcval("create", "string"));
 
1129
.. i18n:         $msg->addParam(new xmlrpcval($arrayVal, "struct"));
 
1130
.. i18n: 
 
1131
.. i18n:         $resp = $client->send($msg);
 
1132
.. i18n: 
 
1133
.. i18n:         if ($resp->faultCode())
 
1134
.. i18n: 
 
1135
.. i18n:             echo 'Error: '.$resp->faultString();
 
1136
.. i18n: 
 
1137
.. i18n:         else
 
1138
.. i18n: 
 
1139
.. i18n:             echo 'Partner '.$resp->value()->scalarval().' created !';
 
1140
.. i18n: 
 
1141
.. i18n:         ?>
 
1142
..
 
1143
 
 
1144
.. code-block:: php
 
1145
 
 
1146
    <?
 
1147
 
 
1148
        include('xmlrpc.inc');
 
1149
 
 
1150
        $arrayVal = array(
 
1151
        'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
 
1152
        'vat'=>new xmlrpcval('BE477472701' , "string")
 
1153
        );
 
1154
 
 
1155
        $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
 
1156
 
 
1157
        $msg = new xmlrpcmsg('execute');
 
1158
        $msg->addParam(new xmlrpcval("dbname", "string"));
 
1159
        $msg->addParam(new xmlrpcval("3", "int"));
 
1160
        $msg->addParam(new xmlrpcval("demo", "string"));
 
1161
        $msg->addParam(new xmlrpcval("res.partner", "string"));
 
1162
        $msg->addParam(new xmlrpcval("create", "string"));
 
1163
        $msg->addParam(new xmlrpcval($arrayVal, "struct"));
 
1164
 
 
1165
        $resp = $client->send($msg);
 
1166
 
 
1167
        if ($resp->faultCode())
 
1168
 
 
1169
            echo 'Error: '.$resp->faultString();
 
1170
 
 
1171
        else
 
1172
 
 
1173
            echo 'Partner '.$resp->value()->scalarval().' created !';
 
1174
 
 
1175
        ?>
 
1176
 
 
1177
.. i18n: Perl Example
 
1178
.. i18n: ------------
 
1179
.. i18n: Here is an example in Perl for creating,searching and deleting a partner.
 
1180
..
 
1181
 
 
1182
Perl Example
 
1183
------------
 
1184
Here is an example in Perl for creating,searching and deleting a partner.
 
1185
 
 
1186
.. i18n: .. code-block:: perl
 
1187
.. i18n: 
 
1188
.. i18n:   #!c:/perl/bin/perl
 
1189
.. i18n:   # 17-02-2010
 
1190
.. i18n:   # OpenERP XML RPC communication example
 
1191
.. i18n:   # Todor Todorov <todorov@hp.com> <tttodorov@yahoo.com>
 
1192
.. i18n: 
 
1193
.. i18n:   use strict;
 
1194
.. i18n:   use Frontier::Client;
 
1195
.. i18n:   use Data::Dumper;
 
1196
.. i18n: 
 
1197
.. i18n:   my($user) = 'admin';
 
1198
.. i18n:   my($pw) = 'admin';
 
1199
.. i18n:   my($db) = 'put_your_dbname_here';
 
1200
.. i18n:   my($model) = 'res.partner';
 
1201
.. i18n: 
 
1202
.. i18n:   #login
 
1203
.. i18n:   my $server_url = 'http://localhost:8069/xmlrpc/common';
 
1204
.. i18n:   my $server = Frontier::Client->new('url' => $server_url);
 
1205
.. i18n:   my $uid = $server->call('login',$db,$user,$pw);
 
1206
.. i18n: 
 
1207
.. i18n:   print Dumper($uid);
 
1208
.. i18n: 
 
1209
.. i18n:   my $server_url = 'http://localhost:8069/xmlrpc/object';
 
1210
.. i18n:   my $server = Frontier::Client->new('url' => $server_url);
 
1211
.. i18n: 
 
1212
.. i18n:   print Dumper($server);
 
1213
.. i18n: 
 
1214
.. i18n:   #
 
1215
.. i18n:   # CREATE A PARTNER
 
1216
.. i18n:   #
 
1217
.. i18n:   my $partner_data = {'name'=>'MyNewPartnerName',
 
1218
.. i18n:                     'active'=> 'True',
 
1219
.. i18n:             'vat'=>'ZZZZZ'};
 
1220
.. i18n:   my $partner_id = $server->call('execute',$db, $uid, $pw, $model, 'create', $partner_data);
 
1221
.. i18n: 
 
1222
.. i18n:   print Dumper($partner_id);
 
1223
.. i18n: 
 
1224
.. i18n:   #
 
1225
.. i18n:   # SEARCH PARTNERS
 
1226
.. i18n:   #
 
1227
.. i18n:   my $query = [['vat', '=', 'ZZZZZ']];
 
1228
.. i18n: 
 
1229
.. i18n:   print Dumper($query);
 
1230
.. i18n: 
 
1231
.. i18n:   my $ids = $server->call('execute',$db, $uid, $pw, $model, 'search', $query);
 
1232
.. i18n: 
 
1233
.. i18n:   print Dumper($ids);
 
1234
.. i18n: 
 
1235
.. i18n:   #Here waiting for user input
 
1236
.. i18n:   #OpenERP interface my be checked if partner is shown there
 
1237
.. i18n: 
 
1238
.. i18n:   print $/."Check OpenERP if partner is inserted. Press ENTER".$/;
 
1239
.. i18n:   <STDIN>;
 
1240
.. i18n: 
 
1241
.. i18n:   #
 
1242
.. i18n:   # DELETE PARTNER DATA
 
1243
.. i18n:   #
 
1244
.. i18n:   my $results = $server->call('execute',$db, $uid, $pw, $model, 'unlink', $ids);
 
1245
.. i18n: 
 
1246
.. i18n:   print Dumper($results);
 
1247
..
 
1248
 
 
1249
.. code-block:: perl
 
1250
 
 
1251
  #!c:/perl/bin/perl
 
1252
  # 17-02-2010
 
1253
  # OpenERP XML RPC communication example
 
1254
  # Todor Todorov <todorov@hp.com> <tttodorov@yahoo.com>
 
1255
 
 
1256
  use strict;
 
1257
  use Frontier::Client;
 
1258
  use Data::Dumper;
 
1259
 
 
1260
  my($user) = 'admin';
 
1261
  my($pw) = 'admin';
 
1262
  my($db) = 'put_your_dbname_here';
 
1263
  my($model) = 'res.partner';
 
1264
 
 
1265
  #login
 
1266
  my $server_url = 'http://localhost:8069/xmlrpc/common';
 
1267
  my $server = Frontier::Client->new('url' => $server_url);
 
1268
  my $uid = $server->call('login',$db,$user,$pw);
 
1269
 
 
1270
  print Dumper($uid);
 
1271
 
 
1272
  my $server_url = 'http://localhost:8069/xmlrpc/object';
 
1273
  my $server = Frontier::Client->new('url' => $server_url);
 
1274
 
 
1275
  print Dumper($server);
 
1276
 
 
1277
  #
 
1278
  # CREATE A PARTNER
 
1279
  #
 
1280
  my $partner_data = {'name'=>'MyNewPartnerName',
 
1281
                    'active'=> 'True',
 
1282
            'vat'=>'ZZZZZ'};
 
1283
  my $partner_id = $server->call('execute',$db, $uid, $pw, $model, 'create', $partner_data);
 
1284
 
 
1285
  print Dumper($partner_id);
 
1286
 
 
1287
  #
 
1288
  # SEARCH PARTNERS
 
1289
  #
 
1290
  my $query = [['vat', '=', 'ZZZZZ']];
 
1291
 
 
1292
  print Dumper($query);
 
1293
 
 
1294
  my $ids = $server->call('execute',$db, $uid, $pw, $model, 'search', $query);
 
1295
 
 
1296
  print Dumper($ids);
 
1297
 
 
1298
  #Here waiting for user input
 
1299
  #OpenERP interface my be checked if partner is shown there
 
1300
 
 
1301
  print $/."Check OpenERP if partner is inserted. Press ENTER".$/;
 
1302
  <STDIN>;
 
1303
 
 
1304
  #
 
1305
  # DELETE PARTNER DATA
 
1306
  #
 
1307
  my $results = $server->call('execute',$db, $uid, $pw, $model, 'unlink', $ids);
 
1308
 
 
1309
  print Dumper($results);
 
1310
 
 
1311
.. i18n: Everything done in the GTK or web client in OpenERP is through XML/RPC webservices. Start openERP GTK client
 
1312
.. i18n: using ./openerp-client.py -l debug_rpc (or debug_rpc_answer) then do what you want in the GTK client and watch
 
1313
.. i18n: your client logs, you will find out the webservice signatures. By creating indents in the logs will help you to
 
1314
.. i18n: spot which webservice you want.
 
1315
..
 
1316
 
 
1317
Everything done in the GTK or web client in OpenERP is through XML/RPC webservices. Start openERP GTK client
 
1318
using ./openerp-client.py -l debug_rpc (or debug_rpc_answer) then do what you want in the GTK client and watch
 
1319
your client logs, you will find out the webservice signatures. By creating indents in the logs will help you to
 
1320
spot which webservice you want.