콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
895 화면

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
355
3
4월 25
4777
0
6월 24
1442
1
1월 24
2173
5
11월 23
43142