コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
791 ビュー

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

アバター
破棄
関連投稿 返信 ビュー 活動
1
7月 25
258
3
4月 25
4643
0
6月 24
1374
1
1月 24
2052
5
11月 23
42958