Odoo Help

Welcome!

This community 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.

0

How could I overwrite only _model in a class?

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

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
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 (SA)
on 1/15/15, 4:06 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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