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,
|
"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,
|
fecha_inicio=fecha, fecha_fin=fecha,
|
||||||
servicios=len(grupo_rows))
|
servicios=len(grupo_rows))
|
||||||
|
|
||||||
@@ -571,18 +571,21 @@ async def run_automation(
|
|||||||
|
|
||||||
def _guardar_envio(user_id, tipo, factura, json_data, respuesta, ok,
|
def _guardar_envio(user_id, tipo, factura, json_data, respuesta, ok,
|
||||||
fecha_inicio=None, fecha_fin=None, servicios=0):
|
fecha_inicio=None, fecha_fin=None, servicios=0):
|
||||||
conn = get_connection()
|
try:
|
||||||
conn.execute("""
|
conn = get_connection()
|
||||||
INSERT INTO envios (user_id, tipo, factura, fecha_inicio, fecha_fin,
|
conn.execute("""
|
||||||
pacientes_count, servicios_count, status, json_enviado, respuesta_api, created_at)
|
INSERT INTO envios (user_id, tipo, factura, fecha_inicio, fecha_fin,
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
pacientes_count, servicios_count, status, json_enviado, respuesta_api, created_at)
|
||||||
""", (
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
user_id, tipo, factura, fecha_inicio, fecha_fin,
|
""", (
|
||||||
1, servicios,
|
user_id, tipo, factura, fecha_inicio, fecha_fin,
|
||||||
"success" if ok else "error",
|
1, servicios,
|
||||||
json_lib.dumps(json_data, indent=2, ensure_ascii=False)[:5000],
|
"success" if ok else "error",
|
||||||
respuesta[:1000] if respuesta else "",
|
json_lib.dumps(json_data, indent=2, ensure_ascii=False)[:5000],
|
||||||
datetime.now().isoformat(),
|
respuesta[:1000] if respuesta else "",
|
||||||
))
|
datetime.now().isoformat(),
|
||||||
conn.commit()
|
))
|
||||||
conn.close()
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user