diff --git a/app/routes/automation.py b/app/routes/automation.py index 3f4684e..8f2988e 100644 --- a/app/routes/automation.py +++ b/app/routes/automation.py @@ -554,7 +554,7 @@ async def run_automation( "ok": ok, "msg": msg, }) - _guardar_envio(user["user_id"], "preserv", factura_ps, rda_json, msg, ok, + _guardar_envio(user["user_id"], "transaccion", factura_ps, rda_json, msg, ok, fecha_inicio=fecha, fecha_fin=fecha, servicios=len(grupo_rows)) @@ -571,18 +571,21 @@ async def run_automation( def _guardar_envio(user_id, tipo, factura, json_data, respuesta, ok, fecha_inicio=None, fecha_fin=None, servicios=0): - conn = get_connection() - conn.execute(""" - INSERT INTO envios (user_id, tipo, factura, fecha_inicio, fecha_fin, - pacientes_count, servicios_count, status, json_enviado, respuesta_api, created_at) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - """, ( - user_id, tipo, factura, fecha_inicio, fecha_fin, - 1, servicios, - "success" if ok else "error", - json_lib.dumps(json_data, indent=2, ensure_ascii=False)[:5000], - respuesta[:1000] if respuesta else "", - datetime.now().isoformat(), - )) - conn.commit() - conn.close() + try: + conn = get_connection() + conn.execute(""" + INSERT INTO envios (user_id, tipo, factura, fecha_inicio, fecha_fin, + pacientes_count, servicios_count, status, json_enviado, respuesta_api, created_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """, ( + user_id, tipo, factura, fecha_inicio, fecha_fin, + 1, servicios, + "success" if ok else "error", + json_lib.dumps(json_data, indent=2, ensure_ascii=False)[:5000], + respuesta[:1000] if respuesta else "", + datetime.now().isoformat(), + )) + conn.commit() + conn.close() + except Exception: + pass