Odoo Help

0

[SOLVED] OpenERP 7: Tree view - Order by date of creation and not by name

By
Selverine
on 5/16/15, 11:09 AM 4,238 views

Hi all,


I would like to know if it is possible, to order the customers by creation date and not by name.

I would like to do it on the "Tree View" in the sale part.

For OpenERP 8 , I can  override the python default order in the tree view

<tree default_order='create_date'> 

</tree>

But it doesn't work for OpenERP 7. 

Are they another possibility?


Someone has an idea please?


Thank you,


Selverine

2
Temur
On 5/18/15, 6:57 AM

in v7 try to add create_date field to the corresponding model:

_columns = {
    'create_date': fields.datetime('Create Date'),
    ...
}
_order = "create_date" # To order using create_date

you have not to manage 'create_date' field in any way, it'll be managed automatically. just add it.

then update module and try again. hope it'll help.

Hi Temur, Thank you for your answer. However, even with this, my Tree order automatically by name and not by create_date. So after I can manually order it with the view interface but I would like automatically by create_date and not by name. Btw why it is automatically by name? Thank you, Selverine

Selverine
on 5/24/15, 4:55 AM

additionally to add 'create_date', use _order in a model, as suggested @Ray:

_order = "create_date"
then it'll be ordered automatically.
also it may be good idea to add readonly=True to create_date field, as it's special field and users do not have to edit it, it's managed by server.
Temur
on 5/25/15, 3:42 AM

Hi Temur. It is still not working...it is still ordering by name. Maybe in another part some function override my order no?

Selverine
on 5/30/15, 5:48 AM

Hi Selverine. yes, that's possible if you're adding changes in a original code, then it may be overriden by module inheriting from module you're changing code in. You should do the stuff (add "create_date" and "_order") in your own custom module, NOT in a base code of Odoo modules(in general it's a bed idea to change anything in original code of base modules). Inherit corresponding model in the custom module and to stuff there, then add model's original module to dependency list of your module ("depends" - in __openerp__.py) and your module will override behavior of original model. if you find that it's overriden in another module, then add that module to "depends" list to overcome it's definitions.

Temur
on 6/1/15, 5:50 AM
1
Ray Carnes
On 5/24/15, 12:00 PM

The way to define the sort order of a model in Python is with:

_order = "first_field, optional_second_field"

If there is no order specified, the default is ID.

Check the documentation at https://www.odoo.com/documentation/8.0/reference/orm.html


Hi Ray. Thank you for your help. I did this inside my class class res_partner(osv.osv, format_address) ( res_partner.py inside the folder /base/res). However it is still not working and it ordered by name and not my create_date. Maybe somewhere a class override my order no? Thank you. Selverine

Selverine
on 5/30/15, 5:46 AM

Selverine, you should not be changing code Odoo code (in the base/res folder). You should make your own module. You can see which modules could be changing the defaults for res.partner by looking in Settings --> Technical --> Database Structure --> Models. Open the res.partner module and look at the 'In Modules' field - this shows you a list of all modules that are contributing to the definition of the model, and that could be changing the default sort order.

Bista Solutions US, Ray Carnes
on 6/2/15, 8:24 AM
0
Selverine
On 6/3/15, 10:35 AM

It is working :-).

Thank you both for your help.

So it was this. One module override the order.

After override it by a new class directly in the sale module it is working perfectly.


Thank you!!

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.

Register

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)

Stats

Asked: 5/16/15, 11:09 AM
Seen: 4238 times
Last updated: 6/17/15, 8:48 AM