How to order a table_query


I want to order a o2m field that points to the next table_query class which join stock_move, stock_location and stock_lot tables:

    def table_query(cls):
        pool = Pool()
        Move = pool.get('stock.move')
        Location = pool.get('stock.location')
        Lot = pool.get('stock.lot')
        table = Move.__table__()
        lot = Lot.__table__()
        location = Location.__table__()
        group_by = []
        for name in ['company', 'product', 'shipment', 'production_input',
                'production_output', 'from_location', 'to_location', 'state',
            group_by.append(Column(table, name))
        group_by.append(Column(location, 'name'))
        columns = [] + group_by
        columns.append(StringAgg(Coalesce(lot.number, ''), ',').as_('lots'))
        return table.join(lot, type_='LEFT',
            condition=( == table.lot)).join(
                location, type_='LEFT', condition=( == table.from_location)).select(*columns,
                group_by=group_by, order_by=(

I expect the o2m to be order by from_location name and I tried different queries but it never returns me the moves ordered. I am missing something?

Thanks in advice.

There is no point to define an order on the table query. The ORM will apply the order defined as usual. So for a One2Many, it is the order defined on the field or the default order defined on the target Model.