Hello,
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:
@classmethod
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',
'description']:
group_by.append(Column(table, name))
group_by.append(Column(location, 'name'))
columns = [] + group_by
columns.append(Max(table.id).as_('id'))
columns.append(Max(table.create_date).as_('create_date'))
columns.append(Max(table.create_uid).as_('create_uid'))
columns.append(Max(table.write_uid).as_('write_uid'))
columns.append(Max(table.write_date).as_('write_date'))
columns.append(Sum(table.internal_quantity).as_('quantity'))
columns.append(StringAgg(Coalesce(lot.number, ''), ',').as_('lots'))
return table.join(lot, type_='LEFT',
condition=(lot.id == table.lot)).join(
location, type_='LEFT', condition=(location.id == table.from_location)).select(*columns,
group_by=group_by, order_by=(location.name))
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.