fix(alerts): limit alerts to 500 per type in SQL + frontend pagination with 'Ver más' + summary bar

This commit is contained in:
2026-05-26 09:12:09 +00:00
parent 3009ffa1b0
commit 61bf84b2dc
4 changed files with 109 additions and 54 deletions

View File

@@ -1111,9 +1111,18 @@ def api_alerts():
"""Get stock alerts (zero, low, over)."""
conn = get_tenant_conn(g.tenant_id)
branch_id = request.args.get('branch_id', g.branch_id)
alerts = get_alerts(conn, branch_id)
limit = min(int(request.args.get('limit', 500)), 2000)
alerts = get_alerts(conn, branch_id, limit_per_type=limit)
conn.close()
return jsonify({'data': alerts, 'count': len(alerts)})
# Count totals by severity for UI summary
counts = {'critical': 0, 'warning': 0, 'info': 0, 'total': 0}
for a in alerts:
counts['total'] += 1
if a['severity'] in counts:
counts[a['severity']] += 1
return jsonify({'data': alerts, 'count': len(alerts), 'counts': counts, 'limit_per_type': limit})
@inventory_bp.route('/items/<int:item_id>/history', methods=['GET'])