跳至內容
選單
此問題已被標幟
2 回覆
2501 瀏覽次數

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

頭像
捨棄