Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
2464 Zobrazení

Hello,

i have the following data.xml:

<record id="hd_general" model="videc.helpdesk.product">                <field name="name">Allgemeinfield>    

record>


How can i get the Database ID by id="hd_general" ?


Avatar
Zrušit
Nejlepší odpověď

Hi,
Using the self.env.ref you can get the database id of the record.

For example, if the module name is sales_extended and record id is hd_general, then the external id of the record will be sales_extended.hd_general

Now you have to pass this external id to the self.env.ref : self.env.ref('sales_extended.hd_general') which will give the record set of the record, then using .id you can get the database id of the record

self.env.ref('sales_extended.hd_general', raise_if_not_found=False)

Along with it you can pass raise_if_not_found=False not to race the error, when the record is deleted from the db


Thanks

Avatar
Zrušit
Nejlepší odpověď

Hi,

You can get the database ID by using the record ID as follows:-

id = self.env.ref('module_name.hd_general').id

instead of module_name add your module_name in which the data file is added


Hope it helps

Avatar
Zrušit