El 01/02/18 a les 04:57, Josias Pérez ha escrit:
> Hola,
>
> Tengo el siguiente método de table_query y las siguientes tablas:
>
> class Gp:
> name
>
> class Reporte
> fecha_inicio
> fecha_fin
> distrito
>
> class ReporteLine
> reporte many2one Reporte
> gp many2one Gp
> cantidad
>
> Deseo encontrar los grupos que no generan reportes, es decir sean NULL o
> cero. Si existe un registro en la clase ReporteLine se puede sumar
> (aunque sea 0), pero si no existe un registro no sé como obtener el
> nombre del grupo (Gp) que no está registrado en ReporteLine.
>
> Tengo el siguiente table_query pero devuelve un valor de error al
> realizar la consulta y devuelve el siguiente error
> ProgrammingError: syntax error at or near ")"
Por el error parece que te falta/sobra algun parentesis.
De todos modos, si nos pones la traza completa mejor.
>
> Cualquier comentario será de mucha ayuda.
>
> def table_query():
> pool = Pool()
> context = Transaction().context
> Gp = pool.get('disc.gp')
> gp = Gp.__table__()
> Reporte = pool.get('disc.reporte')
> reporte = Reporte.__table__()
> ReporteLinea = pool.get('disc.reporte.linea')
> reporte_linea = ReporteLinea.__table__()
>
> where = Literal(True)
> if Transaction().context.get('fecha_inicio'):
> where &= reporte.fecha_inicio >=
> Transaction().context['fecha_inicio']
> if Transaction().context.get('fecha_fin'):
> where &= reporte.fecha_fin <= Transaction().context['fecha_fin']
>
> where &= gp.id == None
Una sugerencia: En vez de instanciar el context varias veces es mejor hacer:
context = Transaction().context
y a partir d'aqui context.get('fecha_inicio')
Queda más limpio.
>
> query1 = reporte.join(reporte_linea,
> condition=reporte_linea.reporte == reporte.id).select(
> Max(reporte_linea.id * 1000).as_('id'),
> Max(reporte.create_uid).as_('create_uid'),
> Max(reporte.create_date).as_('create_date'),
> Max(reporte.write_uid).as_('write_uid'),
> Max(reporte.write_date).as_('write_date'),
> Max(reporte.distrito).as_('distrito'),
> (reporte_linea.gp).as_('gp'),
> Sum(reporte_linea.cantidad).as_('total'),
> group_by=(reporte_linea.gp),
> )
>
> query2 = gp.join(query1,'LEFT').select(
> Max(gp.id * 1001).as_('id'),
> Max(gp.create_uid).as_('create_uid'),
> Max(gp.create_date).as_('create_date'),
> Max(gp.write_uid).as_('write_uid'),
> Max(gp.write_date).as_('write_date'),
> Max(query1.distrito).as_('distrito'),
> (reporte_linea.gp).as_('gp'),
> where = where,
> group_by=(query1.gp),
> )
--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk