This question has been flagged
9 Replies
11198 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

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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

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.
Author

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

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.

Best Answer

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


Avatar
Discard
Author

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, 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.

Author Best Answer

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!!

Avatar
Discard