Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
3527 Ansichten

Hi, I'm trying to retrieve data from odoo using an external api. but I'm having problems when I try to get the external Id. I can't find the corresponding field. could you help me with this? thank you.


here's my code , it's just missing the external id and I don't know how to access it.

  partner_rec= models.execute_kw(db, uid, password, 'res.partner', 'read', [partners], {'fields': ['display_name','phone','email','create_date','zip','activity_ids','city','country_id']})

Avatar
Verwerfen
Autor

i can't. there's no field name specific to this external id i can't access it. there's just the id but it's not the same.

Add 'id' to fields array

Beste Antwort

The external id as far as I understand is not stored in the res.partner model. It is stored for all objects in the ir.model.data model.

you can query this model on the Name field (Name= External ID) and from that get the ResId and the Model fields which contain the Id of the record and the Model this Id belongs to. Similarly, by querying on ResId and Model, you can get the external Id from the Name field.

You can check the contents of this table by looking in Settings - Technical - Sequences&Identifiers - External Identifiers.

Example contents:

Name: person_1

Model: res.partner

ResId: 6503

Avatar
Verwerfen
Beste Antwort

Hi Celia,

You can achieve it by including the x_external_id field in the fields parameter when making the read request.

Try this

partner_rec = models.execute_kw( 
db, uid, password, 'res.partner', 'read', [partners], 
{'fields': ['display_name', 'phone', 'email', 'create_date', 'zip', 'activity_ids', 'city', 'country_id', 'x_external_id']}
)

I hope this helps you.

Avatar
Verwerfen
Autor

Hi, Neha
thank you for your reply but when I added the field 'x_external_id' I got this error: ValueError("Invalid field %r on model %r" % (name, self._name))\nValueError: Invalid field \'x_external_id\' on model \'res.par...

it doesn't recognize the field in fact, I can't figure it out