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

How can i get the last record created in odoo16 ?

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

To get the last record created in Odoo 16, you can use the search() and browse() methods of the corresponding model. Here is an example of how you can do this:

partner_ids = env['res.partner'].search([], order="create_date desc", limit=1)

last_partner = partner_model.browse(partner_ids) # You can now access the fields of the last created partner record

print(last_partner.name)

print(last_partner.email) # etc.

In the code above, we first get a reference to the res.partner model using the env object. Then we use the search() method to find the ID of the last record created, using the order parameter to sort the records by create_date in descending order. We also set a limit of 1 to make sure we only get the last record. We then use the browse() method to retrieve the actual record based on its ID. Finally, we can access the fields of the last created record using the corresponding attributes of the last_partner object.


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

sorry, but i failed to understand what is ' partner_model ' in second line of the solution? i want to search last record in approval.request. please help.

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

Please use the "Last updated on" filter


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

First try to find using Group by option, then if got multiple Records in Same date then Filter on Last Created On 


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 8 25
2636
1
thg 5 25
2655
1
thg 4 25
3646
1
thg 4 25
4504
1
thg 4 25
1974