fix: tipo 'preserv' invalido en CHECK constraint de envios
- Paso 3 usaba tipo='preserv' que no esta en CHECK(tipo IN ('terceros','transaccion'))
- Cambia a 'transaccion' (factura RCXC-XXXXX distingue el registro)
- _guardar_envio con try/except para que error de DB no detenga el loop de envios
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
a47e0a843a
commit
316205466f
+19
-16
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user