Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
18639 Widoki

Hi,

I have a situation where i need to get the XML id of a record from code.For example i need to get the XML id of a user group(Currently i have the id of that particular group).

Thanks

Awatar
Odrzuć

Hope you are looking this:

res = self.env.ref('account.invoice_supplier_form')

Najlepsza odpowiedź

Hi,

You can get it from the table ir.model.data by searching using the id and the model name, suppose if you have to get the external ID of the record with ID 10 in the model res.groups, search like this,

domain = [('model', '=', 'res.groups'), ('res_id', '=', 10)]
model_data = self.env['ir.model.data'].search(domain, limit=1)
xml_id = "%s.%s" % (model_data.module, model_data.name)


To see this table in the UI activate the debug mode and navigate to Settings -> Technical -> Sequence & Identifiers -> External Identifiers

You can see similar example in the odoo code itself, see the _get_external_ids function inside this file https://github.com/odoo/odoo/blob/13.0/odoo/models.py

Thanks

Awatar
Odrzuć
Najlepsza odpowiedź

You can browse record and call the function  get_external_id()

xmlid = record.get_external_id()


Awatar
Odrzuć

also if you want to give an XML ID to ID by accessing Settings > Technical > Sequence & Identifiers > External Identifiers

If your record didn't exist there (by search the ID and models name), just create a new one with your preference external ID, models name, and the record ID

Najlepsza odpowiedź

Using this answer from Ray Carnes this code works for me in Odoo 13:

https://www.odoo.com/es_ES/forum/ayuda-1/how-can-i-show-a-record-s-external-id-in-a-list-view-i-also-want-users-to-be-able-to-search-for-records-using-this-field-146080

product_id = fields.Many2one('product.product', 'Product')
prod_ext_id = fields.Char('ID Ext Product', compute='compute_ext_id_prod')
def compute_ext_id_prod(self):
for record in self:
res = record.product_id.get_external_id()
record.prod_ext_id = False
if res.get(record.product_id.id):
record.prod_ext_id = res.get(record.product_id.id)
I hope it helps!
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
gru 22
3726
1
cze 24
2653
0
paź 23
42898
1
paź 23
4725
2
lut 23
5195