El blog de cubells

Connectar amb odoo per xml-rpc

Ben senzill, llegint la documentació:

$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmlrpclib
>>> 
>>> url = 'http://346030-11-0-dc5e0e.runbot11.odoo.com'
>>> db = '346030-11-0-dc5e0e-all'
>>> username = 'admin'
>>> password = 'admin'
>>> port = ''
>>> common = xmlrpclib.ServerProxy('{url}:{port}/xmlrpc/common'.format(url=url, port=port))
>>> uid = common.authenticate(db, username, password, {})
>>> models = xmlrpclib.ServerProxy('{url}:{port}/xmlrpc/2/object'.format(url=url, port=port))
>>> 
>>> partners = models.execute_kw(db, uid, password, 'res.partner', 'search_read', [[]], {'fields': ['name', 'phone']})
>>> for partner in partners:
...     print('Name: {name}, phone: {phone}'.format(name=partner['name'], phone=partner['phone'] or ''))
... 
Name: ASUSTeK, phone: (+886) (02) 4162 2023
Name: Arthur Gomez, phone: 
Name: James Miller, phone: 
Name: Joseph Walters, phone: 
Name: Julia Rivero, phone: 
Name: Peter Mitchell, phone: 
Name: Tang Tsui, phone: 
Name: Pieter Parter's Farm, phone: 
Name: Agrolait, phone: +32 10 588 558
Name: Edward Foster, phone: 
Name: Laith Jubair, phone: 
Name: Michel Fletcher, phone: 
Name: Thomas Passot, phone: 
Name: Camptocamp, phone: +33 4 49 23 44 54
Name: Ayaan Agarwal, phone: 
Name: Benjamin Flores, phone: 
Name: Phillipp Miller, phone: 
Name: China Export, phone: +86 21 6484 5671
Name: Chao Wang, phone: 
Name: David Simpson, phone: 
Name: Jacob Taylor, phone: 
Name: John M. Brown, phone: 
Name: Coin gourmand, phone: 
Name: Delta PC, phone: +1 510 340 2385
Name: Charlie Bernard, phone: 
Name: Jessica Dupont, phone: 
Name: Kevin Clarke, phone: 
Name: Morgan Rose, phone: 
Name: Richard Ellis, phone: 
Name: Robert Anderson, phone: 
Name: Robin Smith, phone: 
Name: My Company, Chicago, phone: +1 312 349 3030
Name: Steven Hamilton, phone: 
Name: Pizza Inn, phone: 
Name: The Jackson Group, phone: +1 786 525 0724
Name: Daniel Jackson, phone: 
Name: William Thomas, phone: 
Name: Think Big Systems, phone: +1 857 349 3049
Name: Lucas Jones, phone: 
Name: YourCompany, phone: +1 555 123 8069
Name: Administrator, phone: +1 555-555-5555
Name: Demo Portal User, phone: 
Name: Demo User, phone: 
Name: Mark Davis, phone: 
Name: Roger Scott, phone: 
>>> 

Nota: aquest script solament funcionarà fins que maten la màquina virtual.

Sense comentaris encara. Comenta ara