Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
308 Widoki

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

Hi

add in your model python file add _order attribute

_order = 'create_date desc'

example,

Its working file and newly created record first

Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
kwi 25
3536
0
cze 24
910
1
sty 24
1303
5
lis 23
41696
3
wrz 23
8630