fixed bug with user

This commit is contained in:
Ali 2026-04-22 12:59:10 +00:00
parent 8f8a936693
commit 34f0ab2d15
2 changed files with 44 additions and 13 deletions

View File

@ -28,15 +28,22 @@ def finalize(language, company_name):
company_name = (company_name or "").strip() or "Test Company AZ" company_name = (company_name or "").strip() or "Test Company AZ"
year = date.today().year 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 = { args = {
"language": language_name, "language": language_name,
"country": "Azerbaijan", "country": "Azerbaijan",
"timezone": "Asia/Baku", "timezone": "Asia/Baku",
"currency": "AZN", "currency": "AZN",
"enable_telemetry": 0, "enable_telemetry": 0,
# Leave email blank → create_or_update_user is a no-op and Administrator stays. "full_name": session_user.full_name or "Administrator",
"full_name": "", "email": session_user.email or "",
"email": "",
"password": "", "password": "",
"company_name": company_name, "company_name": company_name,
"company_abbr": _make_abbr(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 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: def _make_abbr(name: str) -> str:

View File

@ -142,31 +142,41 @@ frappe.setup.SetupWizard = class JeySetupWizard {
}, },
freeze: true, freeze: true,
callback: (r) => { callback: (r) => {
if (r.message && r.message.status === "ok") { const m = r.message || {};
if (m.status === "ok") {
this.$wrap.find(".jey-body").html( this.$wrap.find(".jey-body").html(
`<p>Setup complete! Redirecting...</p>` `<p>Setup complete! Redirecting...</p>`
); );
setTimeout(() => { setTimeout(() => {
window.location.href = "/app"; window.location.href = "/app";
}, 1500); }, 1500);
} else if (m.status === "error") {
this.show_error(m.failure_message || "Setup failed", m.traceback);
} else { } else {
this.show_error( this.show_error(
"Setup returned unexpected response: " + "Setup returned unexpected response",
JSON.stringify(r.message || {}) JSON.stringify(m, null, 2)
); );
} }
}, },
error: () => { error: () => {
const msg = const resp = frappe.last_response || {};
(frappe.last_response && frappe.last_response.setup_wizard_failure_message) || this.show_error(
"Setup failed — check server logs."; resp.setup_wizard_failure_message || "Setup failed",
this.show_error(msg); resp.exc || resp.exception || ""
);
}, },
}); });
} }
show_error(msg) { show_error(summary, detail) {
this.$wrap.find(".jey-status").text(msg); this.$wrap.find(".jey-body").html(`
<h3 style="color:#c00;margin-bottom:8px">${frappe.utils.escape_html(summary)}</h3>
<pre style="max-height:360px;overflow:auto;background:#f7f7f7;padding:12px;border-radius:4px;font-size:12px;white-space:pre-wrap">${
detail ? frappe.utils.escape_html(String(detail)) : "(no details)"
}</pre>
`);
this.$wrap.find(".jey-status").empty();
this.$wrap.find(".jey-nav") this.$wrap.find(".jey-nav")
.empty() .empty()
.html(`<button class="btn btn-default jey-retry">Retry</button>`) .html(`<button class="btn btn-default jey-retry">Retry</button>`)