61
61
The objects methods
62
62
===================
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
75
75
#. create({'field':'value'})
76
76
* return ID created
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.
150
150
.. i18n: .. code-block:: php
154
.. i18n: include('xmlrpc.inc');
156
.. i18n: $arrayVal = array(
157
.. i18n: 'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
158
.. i18n: 'vat'=>new xmlrpcval('BE477472701' , "string")
161
.. i18n: $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
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"));
171
.. i18n: $resp = $client->send($msg);
173
.. i18n: if ($resp->faultCode())
175
.. i18n: echo 'Error: '.$resp->faultString();
179
.. i18n: echo 'Partner '.$resp->value()->scalarval().' created !';
156
187
include('xmlrpc.inc');
158
.. i18n: include('xmlrpc.inc');
160
189
$arrayVal = array(
161
190
'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
162
191
'vat'=>new xmlrpcval('BE477472701' , "string")
165
.. i18n: $arrayVal = array(
166
.. i18n: 'name'=>new xmlrpcval('Fabien Pinckaers', "string") ,
167
.. i18n: 'vat'=>new xmlrpcval('BE477472701' , "string")
170
194
$client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
172
.. i18n: $client = new xmlrpc_client("http://localhost:8069/xmlrpc/object");
174
196
$msg = new xmlrpcmsg('execute');
175
197
$msg->addParam(new xmlrpcval("dbname", "string"));
176
198
$msg->addParam(new xmlrpcval("3", "int"));
226
226
Example of creation of a partner and his address.
228
228
.. i18n: .. code-block:: python
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'})
239
report = printsock.report_get(dbname, uid, pwd, id_report)
240
state = report['state']
245
print 'Printing aborted, too long delay !'
247
.. i18n: import xmlrpclib
230
.. i18n: import xmlrpclib
232
.. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
234
.. i18n: pwd = 'demo'
237
.. i18n: 'title': 'Monsieur',
238
.. i18n: 'name': 'Fabien Pinckaers',
239
.. i18n: 'lang': 'fr',
240
.. i18n: 'active': True,
243
.. i18n: partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
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',
255
.. i18n: sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
257
.. code-block:: python
249
261
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
253
.. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
255
.. i18n: pwd = 'demo'
258
266
'title': 'Monsieur',
259
267
'name': 'Fabien Pinckaers',
334
304
.. i18n: .. code-block:: python
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'})
345
report = printsock.report_get(dbname, uid, pwd, id_report)
346
state = report['state']
351
print 'Printing aborted, too long delay !'
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
359
.. i18n: import xmlrpclib
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
312
.. i18n: import xmlrpclib
314
.. i18n: user = 'admin'
315
.. i18n: pwd = 'admin'
316
.. i18n: dbname = 'terp3'
317
.. i18n: model = 'res.partner'
319
.. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
320
.. i18n: uid = sock.login(dbname ,user ,pwd)
322
.. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
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)
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
333
.. i18n: # SEARCH PARTNERS
334
.. i18n: args = [('vat', '=', 'ZZZZZ'),]
335
.. i18n: ids = sock.execute(dbname, uid, pwd, model, 'search', args)
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
342
.. i18n: # EDIT PARTNER DATA
343
.. i18n: values = {'vat':'ZZ1ZZ'}
344
.. i18n: results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
346
.. i18n: # DELETE PARTNER DATA
347
.. i18n: results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
349
.. code-block:: python
352
:The login function is under
353
:: http://localhost:8069/xmlrpc/common
354
:For object retrieval use:
355
:: http://localhost:8069/xmlrpc/object
364
362
model = 'res.partner'
366
.. i18n: user = 'admin'
367
.. i18n: pwd = 'admin'
368
.. i18n: dbname = 'terp3'
369
.. i18n: model = 'res.partner'
371
364
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
372
365
uid = sock.login(dbname ,user ,pwd)
374
.. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
375
.. i18n: uid = sock.login(dbname ,user ,pwd)
377
367
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
379
.. i18n: sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
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)
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)
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
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
399
378
# SEARCH PARTNERS
400
379
args = [('vat', '=', 'ZZZZZ'),]
401
380
ids = sock.execute(dbname, uid, pwd, model, 'search', args)
403
.. i18n: # SEARCH PARTNERS
404
.. i18n: args = [('vat', '=', 'ZZZZZ'),]
405
.. i18n: ids = sock.execute(dbname, uid, pwd, model, 'search', args)
407
382
# READ PARTNER DATA
408
383
fields = ['name', 'active', 'vat', 'ref']
409
384
results = sock.execute(dbname, uid, pwd, model, 'read', ids, fields)
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
417
387
# EDIT PARTNER DATA
418
388
values = {'vat':'ZZ1ZZ'}
419
389
results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
421
.. i18n: # EDIT PARTNER DATA
422
.. i18n: values = {'vat':'ZZ1ZZ'}
423
.. i18n: results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
425
# DELETE PARTNER DATA
426
results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
428
.. i18n: # DELETE PARTNER DATA
429
.. i18n: results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
431
391
# DELETE PARTNER DATA
432
392
results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)
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')])
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')])
446
406
.. i18n: .. code-block:: python
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
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 !'
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()
430
.. code-block:: python