Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How To: access the Odoo Online (SAAS) object model using Python

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
pythononlineapixmlrpcodoo16features
1 Răspunde
5611 Vizualizări
Imagine profil
Steve Fossey

Hello all, I thought I would post this challenge I have had.


I am used to other ERPs where the API is RESTful and I found it a real challenge to get data from the online SAAS version of Odoo. Starting with an almost complete lack of documentation and no Swagger page, and ending with the archaic RPC API. But in the end, it is all possible, and seeing as there is very little posted here about how to do stuff like this, I thought I'd share it and hope others will weigh in with things they've worked on too.

First I figured out just how to get a contact with the server:


I used Python just because it was close to hand and I was using it for API calls to Epicor ERP recently.


import requests
import xmlrpc.client
import xml\.etree\.ElementTree\ as\ ET
import\ json

url\ =\ "http://\[myInstance\]\.odoo\.com"
db\ =\ "\[myDatabase\]"
usr\ =\ "myUser"
pwd\ =\ "myPassword"
nl\ =\ "\n"
res\ =\ ""

try:
\ \ \ \
\ \ \ \ common\ =\ xmlrpc\.client\.ServerProxy\('\{\}/xmlrpc/2/common'\.format\(url\)\)
\ \ \ \ uid\ =\ common\.authenticate\(db,\ usr,\ pwd,\ \{\}\)\ \ \
\ \ \ \ data\ =\ json\.dumps\(common\.version\(\)\)
\ \ \ \ for\ k,v\ in\ common\.version\(\)\.items\(\):
\ \ \ \ \ \ \ \ res\ \+=\ str\(k\)\ \+\ ":\ "\ \+\ str\(v\)\ \+\ nl
\ \ \ \ \ \ \ \
except\ Exception\ as\ e:
\ \ \ \ res\ \+=\ "except:\ "\ \+\ str\(e\)\ \+\ nl

finally:
\ \ \ \
\ \ \ \ print\(res\)

This\ got\ me\ the\ basic\ server\ info\ once\ I\ had\ it\ working:



So\ at\ least\ I\ knew\ I\ was\ contacting\ my\ database!


Then\ I\ figured\ out\ code\ to\ get\ me\ partner\ info,\ based\ on\ the\ documentation\.\ Frankly,\ the\ documentation\ leaves\ a\ lot\ out\.\ Maybe\ all\ you\ smart\ people\ already\ know\ how\ to\ parse\ out\ JSON\ and\ so\ on,\ but\ it\ was\ quite\ a\ challenge\ for\ me\.





import\ requests
import\ xmlrpc\.client
import\ json

url\ =\ "http://\[instance\]\.odoo\.com"
db\ =\ "\[dbName\]"
usr\ =\ "userName"
pwd\ =\ "password"
nl\ =\ "\n"
api\ =\ "/xmlrpc/2/"
rslt\ =\ ""
info\ =\ ""

try:

\ \ \ \ \#\ get\ the\ valid\ uid\ of\ an\ authenticated\ API\ user
\ \ \ \ common\ =\ xmlrpc\.client\.ServerProxy\('\{\}/xmlrpc/2/common'\.format\(url\)\)
\ \ \ \ uid\ =\ common\.authenticate\(db,\ usr,\ pwd,\ \{\}\)\ \ \

\ \ \ \ \#\ set\ up\ the\ ServerProxy
\ \ \ \ models\ =\ xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

# check access to the object ("partner" in this case)
access_check = models.execute_kw \
(db, uid, pwd, 'res.partner', 'check_access_rights',\
['read'], {'raise_exception': False})

if access_check == True:
# get the ids of partner objects that only are companies
ids = models.execute_kw(db, uid, pwd, 'res.partner', \
'search', [[['is_company','=', True]]])

# get the fields shown that match the ids
rslt = json.dumps(models.execute_kw (db, uid, pwd, 'res.partner', \
'read', [ids], {'fields': ['name', 'phone']}),indent=1)

data = json.loads(rslt)

for i in data:
info += i["name"] + nl

else:
raise Exception("Model not accessible")

except Exception as e:
rslt += "except: " + str(e) + nl

finally:

print(info)


This allowed me to get a list of partner names where the partner is a company. Odoo's unique model basically makes everybody you know a "Partner", so you then filter to figuer out who is a contact, a company, a vendor, a customer, etc.


Also notice that you first use filters to get the ids related to your search, then you actually read the database based on the ids you return. really weird for someone who grew up with linq, SQL, and REST!


Anyways, this gave me a list of partners that look something like this:



That's all in Python 3.11 and scripted in IDLE by someone who did Python in computer science 10 years ago and hasn't used it since. If I can do it so can you. COmment below, let's get this community interested in posting ideas and cool projects like the big ERPs!

0
Imagine profil
Abandonează
Imagine profil
Niyas Raphy (Walnut Software Solutions)
Cel mai bun răspuns

Hi,
Odoo xml rpc:  https://www.odoo.com/documentation/16.0/developer/reference/external_api.html
Json rpc: https://www.youtube.com/watch?v=J61gRPVSex4

Search Read:  https://www.youtube.com/watch?v=utH3uXkhJfo

Thanks

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
API attachment question
python api xmlrpc
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
iun. 22
7580
ProtocolError for localhost:8069/xmlrpc/2/common: 409 Rezolvat
python api xmlrpc odoo v15
Imagine profil
Imagine profil
2
dec. 22
4899
Add map to my website
development python api googlemaps odoo16features
Imagine profil
0
dec. 22
2325
How to register payment using Python XML-RPC in Odoo 12 Rezolvat
python payment api xmlrpc odoo11
Imagine profil
Imagine profil
Imagine profil
Imagine profil
Imagine profil
5
sept. 19
8980
odoo 9 xmlrpc api returns faultcode 2 when trying to print reports
python api xmlrpc python2.7 odoo9
Imagine profil
0
apr. 18
2483
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now