Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

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

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
pythononlineapixmlrpcodoo16features
1 Svar
5614 Visninger
Avatar
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
Avatar
Kassér
Avatar
Niyas Raphy (Walnut Software Solutions)
Bedste svar

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
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
API attachment question
python api xmlrpc
Avatar
Avatar
Avatar
Avatar
3
jun. 22
7582
ProtocolError for localhost:8069/xmlrpc/2/common: 409 Løst
python api xmlrpc odoo v15
Avatar
Avatar
2
dec. 22
4900
Add map to my website
development python api googlemaps odoo16features
Avatar
0
dec. 22
2325
How to register payment using Python XML-RPC in Odoo 12 Løst
python payment api xmlrpc odoo11
Avatar
Avatar
Avatar
Avatar
Avatar
5
sep. 19
8980
odoo 9 xmlrpc api returns faultcode 2 when trying to print reports
python api xmlrpc python2.7 odoo9
Avatar
0
apr. 18
2483
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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