fix(facturapi): configure legal data after org creation/reuse to enable Live mode
Some checks failed
CI / lint-and-test (3.11) (push) Has been cancelled
CI / lint-and-test (3.13) (push) Has been cancelled

This commit is contained in:
2026-07-09 07:25:07 +00:00
parent 9b88b8ba4c
commit b2f23ef3cf
4 changed files with 110 additions and 31 deletions

View File

@@ -668,14 +668,15 @@ def facturapi_setup():
(result["org_id"],),
)
cur.execute(
"""
INSERT INTO tenant_config (key, value)
VALUES ('cfdi_facturapi_key', %s)
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value
""",
(result["api_key"],),
)
if result.get("api_key"):
cur.execute(
"""
INSERT INTO tenant_config (key, value)
VALUES ('cfdi_facturapi_key', %s)
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value
""",
(result["api_key"],),
)
log_action(conn, "FACTURAPI_SETUP", "tenant_config", None, new_value={"org_id": result["org_id"]})
@@ -683,12 +684,19 @@ def facturapi_setup():
cur.close()
conn.close()
return jsonify(
{
"org_id": result["org_id"],
"message": "Facturapi organization created. Complete pending steps in Facturapi dashboard.",
}
)
status_conn = get_tenant_conn(g.tenant_id)
try:
status_cur = status_conn.cursor()
status = facturapi_service.get_org_status(_get_issuer_config(status_cur))
status["org_id"] = result["org_id"]
if not result.get("legal_updated"):
status["error"] = status.get("error") or "Datos fiscales no pudieron configurarse automáticamente. Configúralos en el dashboard de Facturapi."
status_cur.close()
status_conn.close()
except Exception:
status_conn.close()
raise
return jsonify(status)
except ValueError as e:
conn.rollback()