Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

[Solved] [odoo11] : How to get database ID of external IDs using python external script?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
pythonscriptodoo11
10 Respostes
16716 Vistes
Avatar
Anil Kesariya

Hi All,

Is there any way, we could find the Actual database IDs of records if we have external IDs, using python script.

With XMLRPC or erppeek lib?

For. Eg.

I have 1 table inside odoo with test_test name. Imported some records inside the table using demo data of csv with external ID.

test_001, test_002, so on.

How we could access the data using python script from the table based on these external IDs?

Any idea appreciated.

Rgds,

Anil.

3
Avatar
Descartar
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Best Answer

Hi Anil,

You can call search method using XML-RPC:

rpc_obj.execute(db_name, uid, pwd, 'ir.model.data', 'search', [('model', '=', 'res.partner'), ('name', '=', ext_id)])

Or you can create your own method in custom module and can call it using XML-RPC.

Hope this will help you.

Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
5
Avatar
Descartar
Anil Kesariya
Autor

Thanks sudhir, found solution to get data of csv Id, any idea how to fetch database ID of imported record through xml ID?

Sudhir Arya (ERP Harbor Consulting Services)

Do you want DB ID using XML-RPC?

Anil Kesariya
Autor

Yes. and I have the XML ID of that record as reference.

Sudhir Arya (ERP Harbor Consulting Services)

You can use same code I posted in my answer. When you record of ir.model.data object, get the value of "res_id" field.

Anil Kesariya
Autor

Solved sudhir, thanks for your concerned and answer. :)

Avatar
Anil Kesariya
Autor Best Answer

Hi All,

I have found the solution using ERPPeek lib. which using xmlrpc lib itself.

1. Here is the example, by using I found out Database ID of csv ID.

import erppeek
client = erppeek.Client('http://localhost:8888', 'database_name', 'username', 'pass')
model_data = client.model('ir.model.data')
source_data = model_data.search_read([('model','=','model_name'), ('name','=',external_csv_id)], ['res_id'])

The source data returns database ID as res_id.

This works perfectly if data loaded through csv file.

2. Here is the method Which I have tried to search database ID of record which have been imported  using XML IDs.

import erppeek
client = erppeek.Client('http://localhost:8888', 'database_name', 'username', 'pass')
 model_data = client.model('ir.model.data')
result = model_data.xmlid_lookup("%s.%s" % ('module_name', xml_id))
It returns the list of 3 items.
1 values is backend external ID
2. Model Name
3. Database ID.
o/p E.g. : [2172, 'res.groups', 3]

This is How, I found solution to get the database ID of the records with reference of XML ID.

works like a charm.

Regards,

Anil.


1
Avatar
Descartar
Avatar
David Peralta
Best Answer

Hello

I hope I serve you here I have an example

Example 01:

self.env['ir.model.data'].search_read([('model', '=', 'res.partner'), ('name', '=', 'external_id_csv')], ['res_id'])

return tuple

# [{'res_id': id_database, 'id': id_record_model}]

example 02:

self.env['ir.model.data'].xmlid_to_res_id('your_module.external_id_csv')

1
Avatar
Descartar
Anil Kesariya
Autor

self.env is accessible outside odoo.

Avatar
Florent
Best Answer

There's a simpler solution involving ERPpeek :


----
# Let's say your Odoo module is 'test_module'
# and your csv contains external_ids 'test_001' 'test_002' for "res.partner" records

partner_001 = model("res.partner").get('test_module.test_001')
partner_002 = model("res.partner").get('test_module.test_002')

print(partner_001.id)
print(partner_002.id)


----
0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
Odoo11 sql constraint is not working fine Solved
python script odoo11
Avatar
Avatar
Avatar
3
de gen. 19
7609
How to live rtsp camera in Odoo
python odoo11
Avatar
Avatar
Avatar
2
de jul. 24
15171
[Odoo 11] - Default value for field
script odoo11
Avatar
Avatar
1
de jul. 21
3258
Odoo 11 : _start_new_thread(self._bootstrap, ()) RuntimeError: can't start new thread
python odoo11
Avatar
Avatar
1
de jul. 21
9302
(Automated Action) Problem with write() and do for loop
python odoo11
Avatar
0
d’abr. 20
5712
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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