Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2537 Lượt xem

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


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ