fix(facturapi): configure legal data after org creation/reuse to enable Live mode
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user