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

Hallo

I'm writing a parser for an Aeroo report for expenses.

In the py code I need to make some reference to specific product categories, created within the same module via XML serialization, eg.:


<record id="park" model="product.category"> <field name="parent_id" ref="hr_expense.cat_expense"/> <field name="name">Parking tickets</field> </record>


How can I reference in the py code the category having the id "park"?

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

Hi,

Solution of Serpent Consulting Services Pvt. Ltd. is from V7 and works in V8 as well.
for anyone who is needing it in V8 you can do it in a simpler way with new api

record_id = self.env.ref('module_name.xml_id_of_record').id 
Ảnh đại diện
Huỷ bỏ

still working for odoo v15

Câu trả lời hay nhất

Hello Raffaele,

All the xml records are stored in "ir.model.data" object. There is a method called "get_object_reference" which gives you the database ID from xml ID.

In this method you have to pass module name where xml record is created and xml ID of the record.

Example:

V7:

self.pool.get('ir.model.data').get_object_reference(cr, uid, 'module_name', 'xml_id_of_record')[1]

V8:

record_id = self.env.ref('module_name.xml_id_of_record').id
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 25
1342
0
thg 10 24
1513
1
thg 2 23
2497
0
thg 7 22
1542
3
thg 12 18
5833