~openerp-community/openobject-doc/6.1

« back to all changes in this revision

Viewing changes to i18n/vi/source/developer/17_Web_services/index.rst

  • Committer: TruongSinh Tran
  • Date: 2009-07-19 19:02:35 UTC
  • Revision ID: truongsinh@vipescoserver-20090719190235-fu3bxcrbpvwuk5h7
[FIX] build_i18n.py .. raw:: html

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
How to load data ?
14
14
==================
15
15
 
16
 
   .. i18n: #. Postgresql
17
 
          .. i18n: * Simple, standard
18
 
          .. i18n: * Does not respect the WORKFLOW !!!
19
 
   .. i18n: #. XML files (with –update=)
20
 
   .. i18n: #. XML-RPC
21
 
          .. i18n: * Script, same as website interface
 
16
.. i18n:    #. Postgresql
 
17
.. i18n:           * Simple, standard
 
18
.. i18n:           * Does not respect the WORKFLOW !!!
 
19
.. i18n:    #. XML files (with –update=)
 
20
.. i18n:    #. XML-RPC
 
21
.. i18n:           * Script, same as website interface
22
22
 
23
23
   #. Postgresql
24
24
          * Simple, standard
37
37
 
38
38
:backup:
39
39
 
40
 
    .. i18n: pg_dump terp >terp.sql
 
40
.. i18n:     pg_dump terp >terp.sql
41
41
 
42
42
    pg_dump terp >terp.sql
43
43
 
45
45
 
46
46
:restore:
47
47
 
48
 
    .. i18n: createdb terp --encoding=unicode
49
 
    .. i18n: psql terp < terp.sql
50
 
    .. i18n: or
51
 
    .. i18n: psql -d terp -f terp.sql
 
48
.. i18n:     createdb terp --encoding=unicode
 
49
.. i18n:     psql terp < terp.sql
 
50
.. i18n:     or
 
51
.. i18n:     psql -d terp -f terp.sql
52
52
 
53
53
    createdb terp --encoding=unicode
54
54
    psql terp < terp.sql
61
61
The objects methods
62
62
===================
63
63
 
64
 
   .. i18n: #. create({'field':'value'})
65
 
          .. i18n: * return ID created
66
 
   .. i18n: #. search([('arg1','=','value1')...], offset=0, limit=1000)
67
 
          .. i18n: * return [IDS] found
68
 
   .. i18n: #. read([IDS], ['field1','field2',...])
69
 
          .. i18n: * return [{'id':1, 'field1':..., 'field2':..., ...}, ...]
70
 
   .. i18n: #. write([IDS], {'field1':'value1','field2':3})
71
 
          .. i18n: * return True
72
 
   .. i18n: #. unlink([IDS])
73
 
          .. i18n: * return True
 
64
.. i18n:    #. create({'field':'value'})
 
65
.. i18n:           * return ID created
 
66
.. i18n:    #. search([('arg1','=','value1')...], offset=0, limit=1000)
 
67
.. i18n:           * return [IDS] found
 
68
.. i18n:    #. read([IDS], ['field1','field2',...])
 
69
.. i18n:           * return [{'id':1, 'field1':..., 'field2':..., ...}, ...]
 
70
.. i18n:    #. write([IDS], {'field1':'value1','field2':3})
 
71
.. i18n:           * return True
 
72
.. i18n:    #. unlink([IDS])
 
73
.. i18n:           * return True
74
74
 
75
75
   #. create({'field':'value'})
76
76
          * return ID created
92
92
=================
93
93
 
94
94
.. i18n: #. XML-RPC
95
 
      .. i18n: * standard: http://www.xmlrpc.org
96
 
      .. i18n: * RPC Over HTTP
97
 
      .. i18n: * Function Parameters & Result encoded in XML
 
95
.. i18n:       * standard: http://www.xmlrpc.org
 
96
.. i18n:       * RPC Over HTTP
 
97
.. i18n:       * Function Parameters & Result encoded in XML
98
98
.. i18n: #. Principle;
99
 
      .. i18n: * calls to objects methodes;
100
 
            .. i18n: - read, write
101
 
            .. i18n: - create
102
 
            .. i18n: - unlink (=delete)
 
99
.. i18n:       * calls to objects methodes;
 
100
.. i18n:             - read, write
 
101
.. i18n:             - create
 
102
.. i18n:             - unlink (=delete)
103
103
 
104
104
#. XML-RPC
105
105
      * standard: http://www.xmlrpc.org
148
148
Here is an example on how to insert a new partner using PHP. This example makes use the phpxmlrpc library, available on sourceforge.
149
149
 
150
150
.. i18n: .. code-block:: php
 
151
.. i18n: 
 
152
.. i18n:     <?
 
153
.. i18n: 
 
154
.. i18n:         include('xmlrpc.inc');
 
155
.. i18n: 
 
156
.. i18n:         $arrayVal = array(
 
157
.. i18n:         'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
 
158
.. i18n:         'vat'=>new xmlrpcval('BE477472701' , "string")
 
159
.. i18n:         );
 
160
.. i18n: 
 
161
.. i18n:         $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
 
162
.. i18n: 
 
163
.. i18n:         $msg = new xmlrpcmsg('execute');
 
164
.. i18n:         $msg->addParam(new xmlrpcval("dbname", "string"));
 
165
.. i18n:         $msg->addParam(new xmlrpcval("3", "int"));
 
166
.. i18n:         $msg->addParam(new xmlrpcval("demo", "string"));
 
167
.. i18n:         $msg->addParam(new xmlrpcval("res.partner", "string"));
 
168
.. i18n:         $msg->addParam(new xmlrpcval("create", "string"));
 
169
.. i18n:         $msg->addParam(new xmlrpcval($arrayVal, "struct"));
 
170
.. i18n: 
 
171
.. i18n:         $resp = $client->send($msg);
 
172
.. i18n: 
 
173
.. i18n:         if ($resp->faultCode())
 
174
.. i18n: 
 
175
.. i18n:             echo 'Error: '.$resp->faultString();
 
176
.. i18n: 
 
177
.. i18n:         else
 
178
.. i18n: 
 
179
.. i18n:             echo 'Partner '.$resp->value()->scalarval().' created !';
 
180
.. i18n: 
 
181
.. i18n:     ?>
 
182
 
 
183
.. code-block:: php
151
184
 
152
185
    <?
153
186
 
154
 
    .. i18n: <?
155
 
 
156
187
        include('xmlrpc.inc');
157
188
 
158
 
        .. i18n: include('xmlrpc.inc');
159
 
 
160
189
        $arrayVal = array(
161
190
        'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
162
191
        'vat'=>new xmlrpcval('BE477472701' , "string")
163
192
        );
164
193
 
165
 
        .. i18n: $arrayVal = array(
166
 
        .. i18n: 'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
167
 
        .. i18n: 'vat'=>new xmlrpcval('BE477472701' , "string")
168
 
        .. i18n: );
169
 
 
170
194
        $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
171
195
 
172
 
        .. i18n: $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
173
 
 
174
196
        $msg = new xmlrpcmsg('execute');
175
197
        $msg->addParam(new xmlrpcval("dbname", "string"));
176
198
        $msg->addParam(new xmlrpcval("3", "int"));
179
201
        $msg->addParam(new xmlrpcval("create", "string"));
180
202
        $msg->addParam(new xmlrpcval($arrayVal, "struct"));
181
203
 
182
 
        .. i18n: $msg = new xmlrpcmsg('execute');
183
 
        .. i18n: $msg->addParam(new xmlrpcval("dbname", "string"));
184
 
        .. i18n: $msg->addParam(new xmlrpcval("3", "int"));
185
 
        .. i18n: $msg->addParam(new xmlrpcval("demo", "string"));
186
 
        .. i18n: $msg->addParam(new xmlrpcval("res.partner", "string"));
187
 
        .. i18n: $msg->addParam(new xmlrpcval("create", "string"));
188
 
        .. i18n: $msg->addParam(new xmlrpcval($arrayVal, "struct"));
189
 
 
190
204
        $resp = $client->send($msg);
191
205
 
192
 
        .. i18n: $resp = $client->send($msg);
193
 
 
194
206
        if ($resp->faultCode())
195
207
 
196
 
        .. i18n: if ($resp->faultCode())
197
 
 
198
208
            echo 'Error: '.$resp->faultString();
199
209
 
200
 
            .. i18n: echo 'Error: '.$resp->faultString();
201
 
 
202
210
        else
203
211
 
204
 
        .. i18n: else
205
 
 
206
212
            echo 'Partner '.$resp->value()->scalarval().' created !';
207
213
 
208
 
            .. i18n: echo 'Partner '.$resp->value()->scalarval().' created !';
209
 
 
210
 
    ?>
211
 
 
212
 
    .. i18n: ?>
213
 
 
214
214
    ?>
215
215
 
216
216
.. i18n: ====================
226
226
Example of creation of a partner and his address.
227
227
 
228
228
.. i18n: .. code-block:: python
229
 
 
230
 
    import time
231
 
    import base64
232
 
    printsock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/report')
233
 
    model = 'account.invoice'
234
 
    id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'id': ids[0], 'report_type':'pdf'})
235
 
    time.sleep(5)
236
 
    state = False
237
 
    attempt = 0
238
 
    while not state:
239
 
        report = printsock.report_get(dbname, uid, pwd, id_report)
240
 
        state = report['state']
241
 
        if not state:
242
 
            time.sleep(1)
243
 
            attempt += 1
244
 
        if attempt>200:
245
 
            print 'Printing aborted, too long delay !'
246
 
 
247
 
    .. i18n: import xmlrpclib
 
229
.. i18n: 
 
230
.. i18n:     import xmlrpclib
 
231
.. i18n: 
 
232
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
 
233
.. i18n:     uid = 1
 
234
.. i18n:     pwd = 'demo'
 
235
.. i18n: 
 
236
.. i18n:     partner = {
 
237
.. i18n:         'title': 'Monsieur',
 
238
.. i18n:         'name': 'Fabien Pinckaers',
 
239
.. i18n:         'lang': 'fr',
 
240
.. i18n:         'active': True,
 
241
.. i18n:     }
 
242
.. i18n: 
 
243
.. i18n:     partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
 
244
.. i18n: 
 
245
.. i18n:     address = {
 
246
.. i18n:         'partner_id': partner_id,
 
247
.. i18n:         'type': 'default',
 
248
.. i18n:         'street': 'Rue du vieux chateau, 21',
 
249
.. i18n:         'zip': '1457',
 
250
.. i18n:         'city': 'Walhain',
 
251
.. i18n:         'phone': '(+32)10.68.94.39',
 
252
.. i18n:         'fax': '(+32)10.68.94.39',
 
253
.. i18n:     }
 
254
.. i18n: 
 
255
.. i18n:     sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
 
256
 
 
257
.. code-block:: python
 
258
 
 
259
    import xmlrpclib
248
260
 
249
261
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
250
262
    uid = 1
251
263
    pwd = 'demo'
252
264
 
253
 
    .. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
254
 
    .. i18n: uid = 1
255
 
    .. i18n: pwd = 'demo'
256
 
 
257
265
    partner = {
258
266
        'title': 'Monsieur',
259
267
        'name': 'Fabien Pinckaers',
261
269
        'active': True,
262
270
    }
263
271
 
264
 
    .. i18n: partner = {
265
 
        .. i18n: 'title': 'Monsieur',
266
 
        .. i18n: 'name': 'Fabien Pinckaers',
267
 
        .. i18n: 'lang': 'fr',
268
 
        .. i18n: 'active': True,
269
 
    .. i18n: }
270
 
 
271
272
    partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
272
273
 
273
 
    .. i18n: partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
274
 
 
275
274
    address = {
276
275
        'partner_id': partner_id,
277
276
        'type': 'default',
282
281
        'fax': '(+32)10.68.94.39',
283
282
    }
284
283
 
285
 
    .. i18n: address = {
286
 
        .. i18n: 'partner_id': partner_id,
287
 
        .. i18n: 'type': 'default',
288
 
        .. i18n: 'street': 'Rue du vieux chateau, 21',
289
 
        .. i18n: 'zip': '1457',
290
 
        .. i18n: 'city': 'Walhain',
291
 
        .. i18n: 'phone': '(+32)10.68.94.39',
292
 
        .. i18n: 'fax': '(+32)10.68.94.39',
293
 
    .. i18n: }
294
 
 
295
 
    sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
296
 
 
297
 
    .. i18n: sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
298
 
 
299
284
    sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
300
285
 
301
286
.. i18n: To get the UID of a user, you can use the following script:
303
288
To get the UID of a user, you can use the following script:
304
289
 
305
290
.. i18n: .. code-block:: python
306
 
 
307
 
    import time
308
 
    import base64
309
 
    printsock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/report')
310
 
    model = 'account.invoice'
311
 
    id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'id': ids[0], 'report_type':'pdf'})
312
 
    time.sleep(5)
313
 
    state = False
314
 
    attempt = 0
315
 
    while not state:
316
 
        report = printsock.report_get(dbname, uid, pwd, id_report)
317
 
        state = report['state']
318
 
        if not state:
319
 
            time.sleep(1)
320
 
            attempt += 1
321
 
        if attempt>200:
322
 
            print 'Printing aborted, too long delay !'
323
 
 
324
 
    .. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
325
 
    .. i18n: UID = sock.login('terp3', 'admin', 'admin')
 
291
.. i18n: 
 
292
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
 
293
.. i18n:     UID = sock.login('terp3', 'admin', 'admin')
 
294
 
 
295
.. code-block:: python
326
296
 
327
297
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
328
298
    UID = sock.login('terp3', 'admin', 'admin')
332
302
CRUD example:
333
303
 
334
304
.. i18n: .. code-block:: python
335
 
 
336
 
    import time
337
 
    import base64
338
 
    printsock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/report')
339
 
    model = 'account.invoice'
340
 
    id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'id': ids[0], 'report_type':'pdf'})
341
 
    time.sleep(5)
342
 
    state = False
343
 
    attempt = 0
344
 
    while not state:
345
 
        report = printsock.report_get(dbname, uid, pwd, id_report)
346
 
        state = report['state']
347
 
        if not state:
348
 
            time.sleep(1)
349
 
            attempt += 1
350
 
        if attempt>200:
351
 
            print 'Printing aborted, too long delay !'
352
 
 
353
 
    .. i18n: """
354
 
    .. i18n: :The login function is under
355
 
    .. i18n: ::    http://localhost:8069/xmlrpc/common
356
 
    .. i18n: :For object retrieval use:
357
 
    .. i18n: ::    http://localhost:8069/xmlrpc/object
358
 
    .. i18n: """
359
 
    .. i18n: import xmlrpclib
 
305
.. i18n: 
 
306
.. i18n:     """
 
307
.. i18n:     :The login function is under
 
308
.. i18n:     ::    http://localhost:8069/xmlrpc/common
 
309
.. i18n:     :For object retrieval use:
 
310
.. i18n:     ::    http://localhost:8069/xmlrpc/object
 
311
.. i18n:     """
 
312
.. i18n:     import xmlrpclib
 
313
.. i18n: 
 
314
.. i18n:     user = 'admin'
 
315
.. i18n:     pwd = 'admin'
 
316
.. i18n:     dbname = 'terp3'
 
317
.. i18n:     model = 'res.partner'
 
318
.. i18n: 
 
319
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
 
320
.. i18n:     uid = sock.login(dbname ,user ,pwd)
 
321
.. i18n: 
 
322
.. i18n:     sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
 
323
.. i18n: 
 
324
.. i18n:     # CREATE A PARTNER
 
325
.. i18n:     partner_data = {'name':'Tiny', 'active':True, 'vat':'ZZZZZ'}
 
326
.. i18n:     partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)
 
327
.. i18n: 
 
328
.. i18n:     # The relation between res.partner and res.partner.category is of type many2many
 
329
.. i18n:     # To add  categories to a partner use the following format:
 
330
.. i18n:     partner_data = {'name':'Provider2', 'category_id': [(6,0,[3, 2, 1])]}
 
331
.. i18n:     # Where [3, 2, 1] are id fields of lines in res.partner.category
 
332
.. i18n: 
 
333
.. i18n:     # SEARCH PARTNERS
 
334
.. i18n:     args = [('vat', '=', 'ZZZZZ'),]
 
335
.. i18n:     ids = sock.execute(dbname, uid, pwd, model, 'search', args)
 
336
.. i18n: 
 
337
.. i18n:     # READ PARTNER DATA
 
338
.. i18n:     fields = ['name', 'active', 'vat', 'ref']
 
339
.. i18n:     results = sock.execute(dbname, uid, pwd, model, 'read', ids, fields)
 
340
.. i18n:     print results
 
341
.. i18n: 
 
342
.. i18n:     # EDIT PARTNER DATA
 
343
.. i18n:     values = {'vat':'ZZ1ZZ'}
 
344
.. i18n:     results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
 
345
.. i18n: 
 
346
.. i18n:     # DELETE PARTNER DATA
 
347
.. i18n:     results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
 
348
 
 
349
.. code-block:: python
 
350
 
 
351
    """
 
352
    :The login function is under
 
353
    ::    http://localhost:8069/xmlrpc/common
 
354
    :For object retrieval use:
 
355
    ::    http://localhost:8069/xmlrpc/object
 
356
    """
 
357
    import xmlrpclib
360
358
 
361
359
    user = 'admin'
362
360
    pwd = 'admin'
363
361
    dbname = 'terp3'
364
362
    model = 'res.partner'
365
363
 
366
 
    .. i18n: user = 'admin'
367
 
    .. i18n: pwd = 'admin'
368
 
    .. i18n: dbname = 'terp3'
369
 
    .. i18n: model = 'res.partner'
370
 
 
371
364
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
372
365
    uid = sock.login(dbname ,user ,pwd)
373
366
 
374
 
    .. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
375
 
    .. i18n: uid = sock.login(dbname ,user ,pwd)
376
 
 
377
367
    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
378
368
 
379
 
    .. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
380
 
 
381
369
    # CREATE A PARTNER
382
370
    partner_data = {'name':'Tiny', 'active':True, 'vat':'ZZZZZ'}
383
371
    partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)
384
372
 
385
 
    .. i18n: # CREATE A PARTNER
386
 
    .. i18n: partner_data = {'name':'Tiny', 'active':True, 'vat':'ZZZZZ'}
387
 
    .. i18n: partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)
388
 
 
389
373
    # The relation between res.partner and res.partner.category is of type many2many
390
374
    # To add  categories to a partner use the following format:
391
375
    partner_data = {'name':'Provider2', 'category_id': [(6,0,[3, 2, 1])]}
392
376
    # Where [3, 2, 1] are id fields of lines in res.partner.category
393
377
 
394
 
    .. i18n: # The relation between res.partner and res.partner.category is of type many2many
395
 
    .. i18n: # To add  categories to a partner use the following format:
396
 
    .. i18n: partner_data = {'name':'Provider2', 'category_id': [(6,0,[3, 2, 1])]}
397
 
    .. i18n: # Where [3, 2, 1] are id fields of lines in res.partner.category
398
 
 
399
378
    # SEARCH PARTNERS
400
379
    args = [('vat', '=', 'ZZZZZ'),]
401
380
    ids = sock.execute(dbname, uid, pwd, model, 'search', args)
402
381
 
403
 
    .. i18n: # SEARCH PARTNERS
404
 
    .. i18n: args = [('vat', '=', 'ZZZZZ'),]
405
 
    .. i18n: ids = sock.execute(dbname, uid, pwd, model, 'search', args)
406
 
 
407
382
    # READ PARTNER DATA
408
383
    fields = ['name', 'active', 'vat', 'ref']
409
384
    results = sock.execute(dbname, uid, pwd, model, 'read', ids, fields)
410
385
    print results
411
386
 
412
 
    .. i18n: # READ PARTNER DATA
413
 
    .. i18n: fields = ['name', 'active', 'vat', 'ref']
414
 
    .. i18n: results = sock.execute(dbname, uid, pwd, model, 'read', ids, fields)
415
 
    .. i18n: print results
416
 
 
417
387
    # EDIT PARTNER DATA
418
388
    values = {'vat':'ZZ1ZZ'}
419
389
    results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
420
390
 
421
 
    .. i18n: # EDIT PARTNER DATA
422
 
    .. i18n: values = {'vat':'ZZ1ZZ'}
423
 
    .. i18n: results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
424
 
 
425
 
    # DELETE PARTNER DATA
426
 
    results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
427
 
 
428
 
    .. i18n: # DELETE PARTNER DATA
429
 
    .. i18n: results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
430
 
 
431
391
    # DELETE PARTNER DATA
432
392
    results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
433
393
 
435
395
 
436
396
:PRINT example:
437
397
 
438
 
   .. i18n: 1. PRINT INVOICE
439
 
   .. i18n: 2. IDS is the invoice ID, as returned by:
440
 
   .. i18n: 3. ids = sock.execute(dbname, uid, pwd, 'account.invoice', 'search', [('number', 'ilike', invoicenumber), ('type', '=', 'out_invoice')])
 
398
.. i18n:    1. PRINT INVOICE
 
399
.. i18n:    2. IDS is the invoice ID, as returned by:
 
400
.. i18n:    3. ids = sock.execute(dbname, uid, pwd, 'account.invoice', 'search', [('number', 'ilike', invoicenumber), ('type', '=', 'out_invoice')])
441
401
 
442
402
   1. PRINT INVOICE
443
403
   2. IDS is the invoice ID, as returned by:
444
404
   3. ids = sock.execute(dbname, uid, pwd, 'account.invoice', 'search', [('number', 'ilike', invoicenumber), ('type', '=', 'out_invoice')])
445
405
 
446
406
.. i18n: .. code-block:: python
 
407
.. i18n: 
 
408
.. i18n:     import time
 
409
.. i18n:     import base64
 
410
.. i18n:     printsock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/report')
 
411
.. i18n:     model = 'account.invoice'
 
412
.. i18n:     id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'id': ids[0], 'report_type':'pdf'})
 
413
.. i18n:     time.sleep(5)
 
414
.. i18n:     state = False
 
415
.. i18n:     attempt = 0
 
416
.. i18n:     while not state:
 
417
.. i18n:         report = printsock.report_get(dbname, uid, pwd, id_report)
 
418
.. i18n:         state = report['state']
 
419
.. i18n:         if not state:
 
420
.. i18n:             time.sleep(1)
 
421
.. i18n:             attempt += 1
 
422
.. i18n:         if attempt>200:
 
423
.. i18n:             print 'Printing aborted, too long delay !'
 
424
.. i18n: 
 
425
.. i18n:         string_pdf = base64.decodestring(report['result'])
 
426
.. i18n:         file_pdf = open('/tmp/file.pdf','w')
 
427
.. i18n:         file_pdf.write(string_pdf)
 
428
.. i18n:         file_pdf.close()
 
429
 
 
430
.. code-block:: python
447
431
 
448
432
    import time
449
433
    import base64
462
446
        if attempt>200:
463
447
            print 'Printing aborted, too long delay !'
464
448
 
465
 
    .. i18n: import time
466
 
    .. i18n: import base64
467
 
    .. i18n: printsock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/report')
468
 
    .. i18n: model = 'account.invoice'
469
 
    .. i18n: id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'id': ids[0], 'report_type':'pdf'})
470
 
    .. i18n: time.sleep(5)
471
 
    .. i18n: state = False
472
 
    .. i18n: attempt = 0
473
 
    .. i18n: while not state:
474
 
        .. i18n: report = printsock.report_get(dbname, uid, pwd, id_report)
475
 
        .. i18n: state = report['state']
476
 
        .. i18n: if not state:
477
 
            .. i18n: time.sleep(1)
478
 
            .. i18n: attempt += 1
479
 
        .. i18n: if attempt>200:
480
 
            .. i18n: print 'Printing aborted, too long delay !'
481
 
 
482
 
        string_pdf = base64.decodestring(report['result'])
483
 
        file_pdf = open('/tmp/file.pdf','w')
484
 
        file_pdf.write(string_pdf)
485
 
        file_pdf.close()
486
 
 
487
 
        .. i18n: string_pdf = base64.decodestring(report['result'])
488
 
        .. i18n: file_pdf = open('/tmp/file.pdf','w')
489
 
        .. i18n: file_pdf.write(string_pdf)
490
 
        .. i18n: file_pdf.close()
491
 
 
492
449
        string_pdf = base64.decodestring(report['result'])
493
450
        file_pdf = open('/tmp/file.pdf','w')
494
451
        file_pdf.write(string_pdf)