Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
903 Vistas

Hi,

I'm starting to use the external API, I see some example in the Odoo documentation, but it's not exhaustive.

For example: I need to extract all the clients that have field_X that is empty or that has field_Y that is not something, how do I do that?


P.s. I'm not a developer, but I can do...something! :)

Avatar
Descartar
Mejor respuesta

This piece of code seems working for your needs.

import xmlrpc.client

class PartnerProxy():
​def__init__(self, url, db, user, password):
​self.url = url
​self.db = db
​self.user = user
​self.password = password
​self.uid = self.__get_uid()
​self.models = self.__get_models()

​def__get_auth(self):
​return xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(self.url))

​​def__get_models(self):
​return xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(self.url))

​def__get_uid(self):
​auth = self.__get_auth()
​uid = auth.authenticate(self.db, self.user, self.password, {})
​return uid

​def get_partners(self):
​search_domain = [['field_X', '=', False],                          
​['field_Y', '!=', 'not-this-value']]
​ids = self.models.execute_kw(self.db, self.uid, self.password, 'res.partner',                                       ​'search', [search_domain])
​partners = self.models.execute_kw(self.db, self.uid, self.password, 'res.partner', 'read', [ids], {'fields': ​['name', 'email']})
​return partners

if__name__ == '__main__':
​proxy = PartnerProxy('your-odoo-site-url', 'db', 'your-user-email', 'your-user-password')
​partners = proxy.get_partners()
​print(partners)
Avatar
Descartar