Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
803 มุมมอง

In Odoo 16, how can I configure my model so that newly created records appear at the top of tree views by default?

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

In your model's Python file, set the _order attribute to 'id desc' as shown below:

from odoo import models, fields 
class YourModel(models.Model): 
 _name = 'your.model' 
 _description = 'Your Model Description' 
 _order = 'id desc'

Alternative: Use the create_date Field:
_order = 'create_date desc'

Note:
The _order attribute sets the default sorting for all views associated with the model. If you need different sorting orders for different views, you can specify the default_order attribute directly in the view's XML definition. 

For example:

<tree default_order="create_date desc, id desc">

    <!-- Field definitions -->

</tree>



Best Regards,

NIZAMUDHEEN MJ
Accurates

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi

add in your model python file add _order attribute

_order = 'create_date desc'

example,

Its working file and newly created record first

Thanks

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 25
279
3
เม.ย. 25
4673
0
มิ.ย. 24
1403
1
ม.ค. 24
2062
5
พ.ย. 23
42981