i have the a function field that returns the last evaluations of a party (evaluations is a table that contains party, date, and project)
how i can add an order?
i tried:
@classmethod
def order_periodo_ultima_eval(cls, tables):
pool = Pool()
party, _ = tables[None]
Clase = pool.get('evaluacion_tecso.party_evaluaciones')
table = Clase.__table__()
subquery = Select([Max(table.fecha_eval).as_('fecha_eval1'), table.evaluado.as_('evaluado1')],
from_=table,
group_by=[table.evaluado])
table = table.join(subquery, condition=(subquery.evaluado1 == table.evaluado) & (subquery.fecha_eval1 == table.fecha_eval))
nombre_tabla = 'evaluacion_tecso_party_evaluaciones'
if nombre_tabla not in tables:
nueva_tabla = Clase.__table__()
nueva_tabla1 = Clase.__table__()
tables[nombre_tabla] = {
None: (nueva_tabla, (nueva_tabla.evaluado == party.id)
),}
tables['subquery'] = {
None: (table, (table.evaluado == party.id) & (table.fecha_eval == nueva_tabla.fecha_eval)
), }
else:
nueva_tabla = tables[nombre_tabla]
return Clase.fecha_eval.convert_order('fecha_eval', tables[nombre_tabla], Clase)
the sql to obtain the information is:
select pp.id, pp."name" , ee.fecha_eval
from party_party pp
join evaluacion_tecso_party_evaluaciones ee on pp.id = ee.evaluado
and ee.fecha_eval = (select max(fecha_eval) from evaluacion_tecso_party_evaluaciones where evaluado = pp.id)