Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
777 Vizualizări

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

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

Hi

add in your model python file add _order attribute

_order = 'create_date desc'

example,

Its working file and newly created record first

Thanks

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
iul. 25
254
3
apr. 25
4612
0
iun. 24
1367
1
ian. 24
2040
5
nov. 23
42943