This question has been flagged
1 Reply
3137 Views

Hello all!

We want to change the default sort order in this view. Actually, thoses lines are sorted by name.

In the file ../openerp/addons/base/ir/ir_sequence_view.py, We have changed :

class ir_sequence(openerp.osv.osv.osv):

    _name = 'ir.sequence'
    _order = 'name'

for :

class ir_sequence(openerp.osv.osv.osv):

    _name = 'ir.sequence'
    _order = 'company_id'

and it works. the sequences are well sorted by company_id in our ir_sequence view :

But now, how could we overwrite ONLY this line ( _order = 'company_id') of the ir_sequence class? Do we have to override all the class?

We already have this in our custom module py file :

class not sure (openerp.osv.osv.osv):

    _name = 'not sure...'
    _order = 'company_id'
    _inherit = 'not sure....'
   

Could you help to complete? THANKS

Avatar
Discard

Not getting clearly. You are talking about which line? Can you guide more?

Do you want to change the "_order", by inheriting?

Author

Yes, i'm searching the SHORTEST override that I could have. My goal is only to change the default order of the view.

Best Answer

Hello Pascal Tremblay,

I guess you want to inherit the class and want to override _order.

You can override or add anything by inheriting the object. Following is the sysntax:

class xyz_xyz(osv.osv):
    _inherit = 'xyz.xyz'
    _order = 'field_name'

In the example xyz.xyz (ir.sequence in your case) is the object name which you want to inherit and can change the sorting by changing the field in _order by default its ascending order. If you want sorting in descending order just write desc after field name in _order

_order = 'field_name desc'

If you want sorting based on more than one field write more fields' name and separate them by comma.

_order = 'field_name1 desc, field_name2 desc'

You can refer inheritance in details in documents: Inheritance in Odoo, Inheritance in V7 

Avatar
Discard
Author

It was EXACTLY what I needed. Thanks a lot misters!

Author

Still a question. How could I sort (with _order) but INVERSED??? You know when we click two times on a column header to sort it.

Author

It's here : https://www.odoo.com/fr_FR/forum/help-1/question/how-to-change-the-order-of-partner-list-14100?sort=latest