Skip to content

Conexión con Odoo mediante XMLRPC

Ignacio Buioli edited this page Apr 14, 2021 · 2 revisions

XMLRPC

Python - xmlrpclib

Conexión a Servidor de Odoo

import xmlrpclib

username = 'admin'                # Odoo user
pwd = 'admin'                     # Odoo password
db = 'odoo'                       # Odoo base de datos
url = 'http://localhost:8069'     # Odoo URL

common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
common.version()

Autentificación (obtener UID)

uid = common.authenticate(db, username, pwd, {})

Search

models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
partner_id = models.execute_kw(db, uid, pwd, 'res.partner', 'search', [[('is_company', '=', True)]])

Write

models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
partner_id = models.execute_kw(db, uid, pwd, 'res.partner', 'write', [[id], vals])

Create

models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
partner_id = models.execute_kw(db, uid, pwd, 'res.partner', 'create', [vals])

Unlink

models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
partner_id = models.execute_kw(db, uid, pwd, 'res.partner', 'unlink', [[id]])
Clone this wiki locally