Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

XML-RPC Fetching Records by External ID

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
xmlrpcexternalid
8 Vastaukset
22642 Näkymät
Avatar
Jason Judge

I would like to fetch records over the API using the external ID of those records. Is there a simple way to do this that I am overlooking, because my current approach seems very convoluted.

Given complete names 'l10n_uk.state_uk_99' and 'l10n_uk.state_uk_98', I would like to fetch the two states they represent.

First I need to split the complete names into modules and names. This gives me module "l10n_uk" and names "state_uk_99" and "state_uk_98". If there are several modules involved, then that is another pain point to work around, but let's assume there is just one.

Now I need to search ir.modules.data for these external IDs using this criteria:

    array(
        array("model", "=", "res.country.state"),
        array("module", "=", "l10n_uk"),
        array("name", "in", array("state_uk_99", "state_uk_98")),
    )

This returns me the two IR model IDs. Then I need to fetch those IR model records - I just want the res_id field:

    $my_api->read('ir.modules.data', array(5310, 5311), array('res_id'));

That gives me an array of two arrays. I need to loop through them to find and collect the res_id IDs.

Now I have those IDs, I can fetch the underlying records:

    $my_api->read('res.country.states', $res_ids);

That gives me the underlying two states behind those original external IDs. BUT those records don't contain the external IDs, so I must make sure I keep the external_id:res_id lookup or distribute the external IDs over the state records I have retrieved.

What a faff! Are there any short cuts? Can I search states directly and somehow include the ir.module.data in the search criteria? When reading the states, can I include the external IDs in the retrived columns?

I realise the relationship between the states and the external IDs will be 1:1 only in context (e.g. for my locale) and may not be 1:1 at the database level, so this probably can't be done any other way. But I do need to ask...

Thanks :-)

0
Avatar
Hylkää
Ray Carnes

I think your approach can benefit from a rethink if your goal is an approach that works widely and not just on a specific database. The purpose of an External ID is to allow integration with external business systems. They are not created when records are entered via the UI, only when imported via CSV or via XML. All of our customers use a global modules for Country and State/Province, so your approach would fail on all of their systems, would fail on systems that use a module other than the 'l10n_uk' module, would fail on systems that renamed that module, and would also fail if people entered in their own 'states'. Perhaps backup and outline the business problem you are trying to solve?

Jason Judge
Tekijä

The business process is simple: there are country states in the ERP, imported from various sources. Each state has an external ID. They have been imported from various sources, and have different IDs in different formats. The external ID is a string. We make no assumptions as to what that string is - it is just a series of characters. We are maintaining the states on another system. On that system, against each state, we are storing the external ID of the matching state on the ERP. States that are added to that external system are given a external ID, then exported to the ERP via a CSV file, where they are imported automatically. This keeps them all in sync, which is in one direction - TO the ERP. And that's it. We have data on another system - the main system - and we push updates to OpenERP. We also have legacy external IDs to deal with, which have been generated by whatever import processes have been used in the past. So my question above is: how do I get at this data through the API? Of course, how this data works is a big game of guesswork without a decent set of documentation, which seems to have been the missing element on this project for a long time. I can only assume that what is there is in the ERP system now, is what is supposed to be there.

Jason Judge
Tekijä

Also we must not forget that the simple action of *exporting* records will create system-generated external IDs for those records that don't have any. My external system cannot __export__.control that, but it still needs to be able to scan and reference and potentially update those records. External IDs can easily become a mish-mash of different formats from different sources, unfortunately.

Jason Judge
Tekijä

@Bole that's useful for fetching a single model name and database ID for a record, based on its complete external ID. It can be done in one API call rather than several, as I described above, which can help performance when only one conversion is needed.

Avatar
Bole
Paras vastaus

To fetch a record by external id, try this method:

some_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, module_name, xml_id)
in your case that would be like:
some_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, l10n_uk, state_uk_99)

and you will have current id for the record..

1
Avatar
Hylkää
Matt Taylor

This answer does not use XML-RPC, as described in the question.

Ray Carnes

some_id = sock.execute(dbname, uid, pwd, 'ir.model.data', 'get_object_reference', 'l10n_uk','state_uk_99'))

Ray Carnes (ray)

You can now do self.env.ref('external.identifier')

Avatar
Jerome Guerriat
Paras vastaus

It may be a bit late, but for future reference, i encountered the same problem and i solved it with the following:

odoo = odoorpc.ODOO(server, port=port)

odoo.login(db, username, password)

country_id = odoo.env['ir.model.data'].get_object_reference('base',country)


where "country" was "ca", "be", "us",...

0
Avatar
Hylkää
Jason Judge
Tekijä

It's never too late when a thread is left hanging :-)

I needed to access these records via XML-RPC from PHP, so local calls (within the Odoo app) like this are no so useful, though do add to the understanding. In the end I created a small package to access the API, and wrapped up the fetches that I detailed in the original post into a single function call, as can be seen here: https://github.com/academe/openerpapi#examples It is as simple for me to use as `$partner = $object->readExternal('res.partner', 'base.my_foo');` and has been happily running for a couple of years now, creating customers, invoices, paying invoices etc. for an expedition booking system.

Jason Judge
Tekijä

`get_object_reference` may also be exposed in the API now. It wasn't back in 2014, so far as I could tell.

Avatar
Guenter Bartsch
Paras vastaus

In Odoo 8 using xmlrpc try something along these lines:

 sock2 = xmlrpclib.ServerProxy("http://127.0.0.1:8069/xmlrpc/2/object")
 res = sock2.execute_kw(dbname, uid, pwd, 'ir.model.data', 'get_object_reference', ['purchase', 'route_warehouse0_buy'], {})


0
Avatar
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
xmlrpc Error when attempting to connect to my local instance Ratkaistu
xmlrpc
Avatar
Avatar
Avatar
3
heinäk. 25
4176
Cannot marshal None unless allow_none is enabled
xmlrpc
Avatar
1
lokak. 24
3033
[SOLVED] Odoo-16 ValueError: External ID not found in the system
externalid
Avatar
Avatar
Avatar
Avatar
3
heinäk. 24
11252
How to run a method from external api as the superuser
xmlrpc
Avatar
Avatar
1
huhtik. 24
3102
<methodName>execute</methodName>
xmlrpc
Avatar
0
syysk. 23
2416
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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