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

Odoo community version 15, I am seeing this behaviour - the browse method returns empty objects if the id's don't exist on the database. I'm interested to know if there's a specific reason for it as it's seems counterintuitive and it confused the hell out of me :). Might be worth making a note in the docs 


ipdb> result = odoo_model.browse([-1,-2,-99999999999999])
ipdb> result
leaf.sample(-1, -2, -99999999999999)
ipdb> len(result)
3
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello lan,

if you want to check that record you browse is exist or not than you can use method 'exists()'. It will return all available records. Check below code.

odoo_model.browse([-1,-2]).exists()


You can also check below links for answer if it helps.

https://stackoverflow.com/a/53932769/10820378

https://stackoverflow.com/a/19226249/10820378

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

Many thanks Siddharth, that's very useful. 

it is interesting that the line to assert that the ids point to existing records is there but commented out. That would hint that this behaviour is not perhaps clear. What is the process for asking for an amendment to the documentation?

Many thanks again, it's very much appreciated.

Ian

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
5581
0
thg 2 24
1374
2
thg 3 21
2711
1
thg 9 19
2183
1
thg 4 15
4255