Using search_order on Many2One

Hi,
Need some help how to user search_order attribute on Many2One field. Don’t find any example in code.
How to sort on specific field following ascending or descending order ?
I try to define a descending order on number when searching lot_number on move:

class Move(metaclass=PoolMeta):
    __name__ = 'stock.move'

    @classmethod
    def __setup__(cls):
        super(Move, cls).__setup__()
        cls.lot.search_order = [(Eval('number'), 'DESC'), ]

Thanks!

It is an order like the ModelSQL._order, the only difference is that it can be a PYSON statement that must returns the usual order clause format.
In your example, it does not generate a valid order clause as Eval('number') will be replaced by the value from the record.
If I understand what you try to achieve you should just use:

 cls.lot.search_order = [('number', 'DESC')]

It’s working. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.