تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
2503 أدوات العرض

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" ?


الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال