Sort by field in super class ( inherited by prototyping )

Asked by Gautam

Hi,
I am trying to sort the employee tree view by the employee name but an simple "_order" will not work because the name is inherited from resource.resource. Is there another way to do this ?

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Gautam
Solved:
Last query:
Last reply:
Revision history for this message
Ferdinand (office-chricar) said :
#1

IMHO OpenERP should provide a class for easy sorting

like opener_sort(class_name, [(column to sort, asc/desc), ....] )
which returns sorted ids

Revision history for this message
Gautam (gditerp) said :
#2

Hi Ferdinand,
I have overriden the search method in the hr_employee class which seems to do the trick.
    def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
        if not order:
            order = "name asc"
        return super(hr_employee, self).search(cr, user, args, offset=offset, limit=limit, order=order,
            context=context, count=count)

However, I still feel the _order should take into account the inherited fields as they do form part of the class.

Revision history for this message
Atul Makwana(SerpentCS) (amakwana-serpentcs) said :
#3

Hello Gautam,
This is the anohter trick to sort the inherited field. You can do the same thing adding the related field in "hr_employee".

 _columns = {
        'resource_name': fields.related('resource_id', 'name', string="Name", type='char', size=128, store=True)
...
}

_order = 'resource_name'