imporve features

This commit is contained in:
Urtzi Alfaro
2025-11-14 07:23:56 +01:00
parent 9bc048d360
commit a8d8828935
32 changed files with 5436 additions and 271 deletions

View File

@@ -92,7 +92,7 @@ class InventoryAlertRepository:
JOIN ingredients i ON s.ingredient_id = i.id
WHERE i.tenant_id = :tenant_id
AND s.is_available = true
AND s.expiration_date <= CURRENT_DATE + INTERVAL ':days_threshold days'
AND s.expiration_date <= CURRENT_DATE + (INTERVAL '1 day' * :days_threshold)
ORDER BY s.expiration_date ASC, total_value DESC
""")
@@ -134,7 +134,7 @@ class InventoryAlertRepository:
FROM temperature_logs tl
WHERE tl.tenant_id = :tenant_id
AND tl.is_within_range = false
AND tl.recorded_at > NOW() - INTERVAL ':hours_back hours'
AND tl.recorded_at > NOW() - (INTERVAL '1 hour' * :hours_back)
AND tl.alert_triggered = false
ORDER BY deviation DESC, tl.recorded_at DESC
""")

View File

@@ -227,9 +227,9 @@ class InventoryAlertService(BaseAlertService, AlertServiceMixin):
"""Process expiring items for a tenant"""
try:
# Group by urgency
expired = [i for i in items if i['days_to_expiry'] <= 0]
urgent = [i for i in items if 0 < i['days_to_expiry'] <= 2]
warning = [i for i in items if 2 < i['days_to_expiry'] <= 7]
expired = [i for i in items if i['days_until_expiry'] <= 0]
urgent = [i for i in items if 0 < i['days_until_expiry'] <= 2]
warning = [i for i in items if 2 < i['days_until_expiry'] <= 7]
# Process expired products (urgent alerts)
if expired:
@@ -257,7 +257,7 @@ class InventoryAlertService(BaseAlertService, AlertServiceMixin):
'name': item['name'],
'stock_id': str(item['stock_id']),
'quantity': float(item['current_quantity']),
'days_expired': abs(item['days_to_expiry'])
'days_expired': abs(item['days_until_expiry'])
} for item in expired
]
}
@@ -270,12 +270,12 @@ class InventoryAlertService(BaseAlertService, AlertServiceMixin):
'type': 'urgent_expiry',
'severity': 'high',
'title': f'⏰ Caducidad Urgente: {item["name"]}',
'message': f'{item["name"]} caduca en {item["days_to_expiry"]} día(s). Usar prioritariamente.',
'message': f'{item["name"]} caduca en {item["days_until_expiry"]} día(s). Usar prioritariamente.',
'actions': ['Usar inmediatamente', 'Promoción especial', 'Revisar recetas', 'Documentar'],
'metadata': {
'ingredient_id': str(item['id']),
'stock_id': str(item['stock_id']),
'days_to_expiry': item['days_to_expiry'],
'days_to_expiry': item['days_until_expiry'],
'quantity': float(item['current_quantity'])
}
}, item_type='alert')