Modulo de Reportes v1 filtro actualizado basico
This commit is contained in:
@@ -1292,10 +1292,18 @@ def get_dashboard_data(
|
||||
|
||||
# Aplicar filtros de fecha
|
||||
if start_date:
|
||||
start = datetime.fromisoformat(start_date)
|
||||
# Parsear fecha y establecer al inicio del día en UTC
|
||||
from datetime import timezone
|
||||
start = datetime.fromisoformat(start_date).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
if start.tzinfo is None:
|
||||
start = start.replace(tzinfo=timezone.utc)
|
||||
query = query.filter(models.Inspection.started_at >= start)
|
||||
if end_date:
|
||||
end = datetime.fromisoformat(end_date)
|
||||
# Parsear fecha y establecer al final del día en UTC
|
||||
from datetime import timezone
|
||||
end = datetime.fromisoformat(end_date).replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
if end.tzinfo is None:
|
||||
end = end.replace(tzinfo=timezone.utc)
|
||||
query = query.filter(models.Inspection.started_at <= end)
|
||||
|
||||
# Filtro por mecánico
|
||||
@@ -1327,10 +1335,16 @@ def get_dashboard_data(
|
||||
.filter(models.Inspection.is_active == True)
|
||||
|
||||
if start_date:
|
||||
start = datetime.fromisoformat(start_date)
|
||||
from datetime import timezone
|
||||
start = datetime.fromisoformat(start_date).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
if start.tzinfo is None:
|
||||
start = start.replace(tzinfo=timezone.utc)
|
||||
flagged_items = flagged_items.filter(models.Inspection.started_at >= start)
|
||||
if end_date:
|
||||
end = datetime.fromisoformat(end_date)
|
||||
from datetime import timezone
|
||||
end = datetime.fromisoformat(end_date).replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
if end.tzinfo is None:
|
||||
end = end.replace(tzinfo=timezone.utc)
|
||||
flagged_items = flagged_items.filter(models.Inspection.started_at <= end)
|
||||
if mechanic_id:
|
||||
flagged_items = flagged_items.filter(models.Inspection.mechanic_id == mechanic_id)
|
||||
@@ -1364,10 +1378,16 @@ def get_dashboard_data(
|
||||
.filter(models.Inspection.is_active == True)
|
||||
|
||||
if start_date:
|
||||
start = datetime.fromisoformat(start_date)
|
||||
from datetime import timezone
|
||||
start = datetime.fromisoformat(start_date).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
if start.tzinfo is None:
|
||||
start = start.replace(tzinfo=timezone.utc)
|
||||
mechanic_stats = mechanic_stats.filter(models.Inspection.started_at >= start)
|
||||
if end_date:
|
||||
end = datetime.fromisoformat(end_date)
|
||||
from datetime import timezone
|
||||
end = datetime.fromisoformat(end_date).replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
if end.tzinfo is None:
|
||||
end = end.replace(tzinfo=timezone.utc)
|
||||
mechanic_stats = mechanic_stats.filter(models.Inspection.started_at <= end)
|
||||
|
||||
mechanic_stats = mechanic_stats.group_by(models.User.id, models.User.full_name)\
|
||||
@@ -1401,10 +1421,16 @@ def get_dashboard_data(
|
||||
.filter(models.Checklist.is_active == True)
|
||||
|
||||
if start_date:
|
||||
start = datetime.fromisoformat(start_date)
|
||||
from datetime import timezone
|
||||
start = datetime.fromisoformat(start_date).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
if start.tzinfo is None:
|
||||
start = start.replace(tzinfo=timezone.utc)
|
||||
checklist_stats_query = checklist_stats_query.filter(models.Inspection.started_at >= start)
|
||||
if end_date:
|
||||
end = datetime.fromisoformat(end_date)
|
||||
from datetime import timezone
|
||||
end = datetime.fromisoformat(end_date).replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
if end.tzinfo is None:
|
||||
end = end.replace(tzinfo=timezone.utc)
|
||||
checklist_stats_query = checklist_stats_query.filter(models.Inspection.started_at <= end)
|
||||
if mechanic_id:
|
||||
checklist_stats_query = checklist_stats_query.filter(models.Inspection.mechanic_id == mechanic_id)
|
||||
@@ -1456,10 +1482,16 @@ def get_dashboard_data(
|
||||
.filter(models.Answer.answer_value.in_(['pass', 'fail', 'good', 'bad', 'regular']))
|
||||
|
||||
if start_date:
|
||||
start = datetime.fromisoformat(start_date)
|
||||
from datetime import timezone
|
||||
start = datetime.fromisoformat(start_date).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
if start.tzinfo is None:
|
||||
start = start.replace(tzinfo=timezone.utc)
|
||||
pass_fail_data = pass_fail_data.filter(models.Inspection.started_at >= start)
|
||||
if end_date:
|
||||
end = datetime.fromisoformat(end_date)
|
||||
from datetime import timezone
|
||||
end = datetime.fromisoformat(end_date).replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
if end.tzinfo is None:
|
||||
end = end.replace(tzinfo=timezone.utc)
|
||||
pass_fail_data = pass_fail_data.filter(models.Inspection.started_at <= end)
|
||||
if mechanic_id:
|
||||
pass_fail_data = pass_fail_data.filter(models.Inspection.mechanic_id == mechanic_id)
|
||||
@@ -1496,6 +1528,7 @@ def get_inspections_report(
|
||||
query = db.query(
|
||||
models.Inspection.id,
|
||||
models.Inspection.vehicle_plate,
|
||||
models.Inspection.checklist_id,
|
||||
models.Checklist.name.label('checklist_name'),
|
||||
models.User.full_name.label('mechanic_name'),
|
||||
models.Inspection.status,
|
||||
@@ -1515,10 +1548,16 @@ def get_inspections_report(
|
||||
|
||||
# Aplicar filtros
|
||||
if start_date:
|
||||
start = datetime.fromisoformat(start_date)
|
||||
from datetime import timezone
|
||||
start = datetime.fromisoformat(start_date).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
if start.tzinfo is None:
|
||||
start = start.replace(tzinfo=timezone.utc)
|
||||
query = query.filter(models.Inspection.started_at >= start)
|
||||
if end_date:
|
||||
end = datetime.fromisoformat(end_date)
|
||||
from datetime import timezone
|
||||
end = datetime.fromisoformat(end_date).replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
if end.tzinfo is None:
|
||||
end = end.replace(tzinfo=timezone.utc)
|
||||
query = query.filter(models.Inspection.started_at <= end)
|
||||
if mechanic_id:
|
||||
query = query.filter(models.Inspection.mechanic_id == mechanic_id)
|
||||
@@ -1541,6 +1580,7 @@ def get_inspections_report(
|
||||
{
|
||||
"id": r.id,
|
||||
"vehicle_plate": r.vehicle_plate,
|
||||
"checklist_id": r.checklist_id,
|
||||
"checklist_name": r.checklist_name,
|
||||
"mechanic_name": r.mechanic_name,
|
||||
"status": r.status,
|
||||
|
||||
Reference in New Issue
Block a user