Odoo Help


How could I overwrite only _model in a class?

Pascal Tremblay
on 1/15/15, 8:25 AM 1,471 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

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

Emipro Technologies Pvt. Ltd.
on 1/15/15, 9:05 AM

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

Emipro Technologies Pvt. Ltd.
on 1/15/15, 9:20 AM

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

Pascal Tremblay
on 1/15/15, 9:23 AM

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 1/15/15, 9:49 AM

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 

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

Pascal Tremblay
on 1/15/15, 9:54 AM

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.

Pascal Tremblay
on 1/15/15, 2:37 PM

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

Pascal Tremblay
on 1/15/15, 2:44 PM

See my updated answer.

Sudhir Arya (ERP Harbor Consulting Services)
on 1/15/15, 4:06 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 1/15/15, 8:25 AM
Seen: 1471 times
Last updated: 3/16/15, 8:10 AM