From 70a600cc662be1d670e98157b86c448fb8aa119f Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Tue, 30 Jun 2026 08:20:04 +0000 Subject: [PATCH] hotfix: corrige 500 en /customers y /historical-sales - customers_bp: last_purchase no existe como columna; se calcula via subquery a sales. - pos_bp: historical_sales no existe en tenants sin importacion; endpoint devuelve lista vacia en lugar de 500. - Servicio reiniciado y validado. Tests: 35 passed --- pos/blueprints/customers_bp.py | 3 ++- pos/blueprints/pos_bp.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pos/blueprints/customers_bp.py b/pos/blueprints/customers_bp.py index b0313a6..1a9613e 100644 --- a/pos/blueprints/customers_bp.py +++ b/pos/blueprints/customers_bp.py @@ -80,7 +80,8 @@ def list_customers(): SELECT c.id, c.name, c.rfc, c.razon_social, c.phone, c.email, c.address, c.cp, c.price_tier, c.credit_limit, c.credit_balance, c.vehicle_info, - c.branch_id, c.is_active, c.created_at, c.last_purchase + c.branch_id, c.is_active, c.created_at, + (SELECT MAX(s.created_at) FROM sales s WHERE s.customer_id = c.id) AS last_purchase FROM customers c WHERE {where} ORDER BY c.name diff --git a/pos/blueprints/pos_bp.py b/pos/blueprints/pos_bp.py index 3f3fc86..220edb8 100644 --- a/pos/blueprints/pos_bp.py +++ b/pos/blueprints/pos_bp.py @@ -338,6 +338,16 @@ def list_historical_sales(): where = " AND ".join(where_clauses) + # Defensive: the historical_sales table is created on demand by imports. + # If it does not exist yet, return an empty list instead of a 500. + cur.execute("SELECT to_regclass('historical_sales')") + if cur.fetchone()[0] is None: + cur.close(); conn.close() + return jsonify({ + 'data': [], + 'pagination': {'page': page, 'per_page': per_page, 'total': 0, 'total_pages': 0} + }) + cur.execute(f"SELECT count(*) FROM historical_sales WHERE {where}", params) total = cur.fetchone()[0]