Good afternoon, I would like to know if you could help me with this problem.
I have this model where I record the sales made by each user on a default date and that is in datetime
now = datetime.datetime.now()
db.define_table('registros_ventas',
Field('usuario', db.usuarios, label=T('Usuario')),
Field('fecha_venta', 'datetime', label=T('Fecha de Venta'), default=now, writable=False),
Field('codigo_venta', 'string', label=T('Codigo de Venta')),
Field('detalle_venta', 'string', label=T('Detalle de Venta')),
Field('tipo_venta', db.tipos_ventas, label=T('Tipo de Venta')),
Field('destino', 'string', label=T('Destino de Venta')),
format='%(id)s'
)
Now, with this model I want to make a query comparing data entered with a sqlform.factory
like this
data = SQLFORM.factory(
Field('usuario', db.usuarios, label=T('Usuario')),
Field('fecha_inicial', 'date'),
Field('fecha_final', 'date'),
)
if form.process().accepted:
usuario = data .vars.usuario
inicio= data .vars.fecha_inicial
fin= data .vars.fecha_final
new_data = db((db.registros_ventas.usuario == usuario) &
((db.registros_ventas.fecha_venta>= fecha_inicial) & (db.registros_ventas.fecha_venta<= fecha_final))
).select(
db.usuarios.usuario,
db.registros_ventas.fecha_venta,
db.registros_ventas.codigo_venta,
db.registros_ventas.detalle_venta,
db.registros_ventas.tipo_venta,
db.registros_ventas.destino,
left=(
db.usuarios.on(db.usuarios.id == db.registros_ventas.usuario),
)
)
return dict(new_data = new_data )
My problem is that I can not make a query comparing the dates in datetime()
with those of type date()
then I tried to change format but I have not obtained results, I would like to know what is the appropriate way to do it and the way to go, someone to support me :(?