diff --git a/jey_wizard/api.py b/jey_wizard/api.py index 373fc7b..e90367b 100644 --- a/jey_wizard/api.py +++ b/jey_wizard/api.py @@ -28,15 +28,22 @@ def finalize(language, company_name): company_name = (company_name or "").strip() or "Test Company AZ" year = date.today().year + # Emulate what the default wizard passes: the email of the current session user. + # Frappe's create_or_update_user uses this to either update the existing user (if the + # row already exists) or create one. Passing blanks here caused downstream hooks that + # assume a real user-record to misbehave. + session_user = frappe.db.get_value( + "User", frappe.session.user, ["full_name", "email"], as_dict=True + ) or frappe._dict() + args = { "language": language_name, "country": "Azerbaijan", "timezone": "Asia/Baku", "currency": "AZN", "enable_telemetry": 0, - # Leave email blank → create_or_update_user is a no-op and Administrator stays. - "full_name": "", - "email": "", + "full_name": session_user.full_name or "Administrator", + "email": session_user.email or "", "password": "", "company_name": company_name, "company_abbr": _make_abbr(company_name), @@ -48,7 +55,21 @@ def finalize(language, company_name): from frappe.desk.page.setup_wizard.setup_wizard import setup_complete - return setup_complete(args) + try: + result = setup_complete(args) + except Exception: + # Surface the traceback to the client so we can see exactly where setup fell over, + # instead of the generic "Setup failed" wrapper. + tb = frappe.get_traceback(with_context=True) + frappe.log_error(title="Jey Wizard finalize failed", message=tb) + return { + "status": "error", + "failure_message": frappe.response.get("setup_wizard_failure_message") + or "Setup failed — see traceback", + "traceback": tb, + } + + return result def _make_abbr(name: str) -> str: diff --git a/jey_wizard/public/js/jey_setup.js b/jey_wizard/public/js/jey_setup.js index 558fb40..0feac78 100644 --- a/jey_wizard/public/js/jey_setup.js +++ b/jey_wizard/public/js/jey_setup.js @@ -142,31 +142,41 @@ frappe.setup.SetupWizard = class JeySetupWizard { }, freeze: true, callback: (r) => { - if (r.message && r.message.status === "ok") { + const m = r.message || {}; + if (m.status === "ok") { this.$wrap.find(".jey-body").html( `
Setup complete! Redirecting...
` ); setTimeout(() => { window.location.href = "/app"; }, 1500); + } else if (m.status === "error") { + this.show_error(m.failure_message || "Setup failed", m.traceback); } else { this.show_error( - "Setup returned unexpected response: " + - JSON.stringify(r.message || {}) + "Setup returned unexpected response", + JSON.stringify(m, null, 2) ); } }, error: () => { - const msg = - (frappe.last_response && frappe.last_response.setup_wizard_failure_message) || - "Setup failed — check server logs."; - this.show_error(msg); + const resp = frappe.last_response || {}; + this.show_error( + resp.setup_wizard_failure_message || "Setup failed", + resp.exc || resp.exception || "" + ); }, }); } - show_error(msg) { - this.$wrap.find(".jey-status").text(msg); + show_error(summary, detail) { + this.$wrap.find(".jey-body").html(` +${
+ detail ? frappe.utils.escape_html(String(detail)) : "(no details)"
+ }
+ `);
+ this.$wrap.find(".jey-status").empty();
this.$wrap.find(".jey-nav")
.empty()
.html(``)