diff --git a/jey_wizard/__init__.py b/jey_wizard/__init__.py index fb69db9..f3b4574 100644 --- a/jey_wizard/__init__.py +++ b/jey_wizard/__init__.py @@ -1 +1 @@ -__version__ = "0.1.14" +__version__ = "0.1.15" diff --git a/jey_wizard/etaxes.py b/jey_wizard/etaxes.py index 5de7f14..ec6da82 100644 --- a/jey_wizard/etaxes.py +++ b/jey_wizard/etaxes.py @@ -200,16 +200,23 @@ def fetch_company_profile(): cache.save() frappe.db.commit() + # Lower-case the raw criteria once so the JS layer can do a simple + # equality check (criteriaOfBusinessEntity arrives capitalised in some + # tenants — "Micro" vs "micro"). + criteria_raw = profile.get("criteriaOfBusinessEntity") if isinstance(profile, dict) else None + criteria = str(criteria_raw).strip().lower() if criteria_raw else "" + frappe.log_error( json.dumps({ "has_profile": bool(profile), "profile_keys": sorted(list(profile.keys())) if isinstance(profile, dict) else None, "resolved": resolved, + "criteria": criteria, }, ensure_ascii=False, indent=2), "Jey Wizard trace: fetch_company_profile done", ) - return {"ok": True, "resolved": resolved} + return {"ok": True, "resolved": resolved, "criteria": criteria} @frappe.whitelist() diff --git a/jey_wizard/public/js/jey_setup.js b/jey_wizard/public/js/jey_setup.js index 7dac559..fc3db77 100644 --- a/jey_wizard/public/js/jey_setup.js +++ b/jey_wizard/public/js/jey_setup.js @@ -10,7 +10,7 @@ frappe.provide("jey_wizard"); // Bump this string in every commit that changes wizard code. Displayed in the badge so // we can tell at a glance which version is actually running on a given machine. Kept in // sync with __version__ in jey_wizard/__init__.py. -const JEY_WIZARD_VERSION = "0.1.14"; +const JEY_WIZARD_VERSION = "0.1.15"; // Wipe Frappe + ERPNext default slides so their `before_load`/`after_load` listeners // don't try to mutate a wizard that isn't slide-based anymore. @@ -54,6 +54,13 @@ frappe.setup.SetupWizard = class JeySetupWizard { fy_end_date: `${year}-12-31`, valuation_method: "FIFO", accounting_method: "Hesablama metodu", + // Auto-pick Kassa for micro entities. Reset to true only when + // fetch_company_profile returns a known criteria — without that + // signal we keep the static default. Toggled to true the moment + // the user touches the select so the criteria heuristic stops + // overwriting their choice. + accounting_method_user_edited: false, + business_criteria: "", // Admin user (fresh user step — Administrator stays untouched) user_full_name: "", user_email: "", @@ -432,7 +439,7 @@ frappe.setup.SetupWizard = class JeySetupWizard { -
${__("Stored in Company → Tax Policy.")}
+
${__("Stored in Company → Tax Policy.")}
`); $body.find(".jey-company-name").val(this.data.company_name); @@ -440,6 +447,21 @@ frappe.setup.SetupWizard = class JeySetupWizard { $body.find(".jey-fy-end").val(this.data.fy_end_date); $body.find(".jey-valuation-method").val(this.data.valuation_method || "FIFO"); $body.find(".jey-accounting-method").val(this.data.accounting_method || "Hesablama metodu"); + // Show why the default landed where it did, only when the auto-pick + // from criteriaOfBusinessEntity was actually applied. + if (this.data.business_criteria && !this.data.accounting_method_user_edited) { + const isMicro = this.data.business_criteria === "micro"; + $body.find(".jey-accounting-hint").text( + isMicro + ? __("Auto-selected because the e-taxes profile classifies this entity as Micro.") + : __("Auto-selected because the e-taxes profile classifies this entity as {0}.", [this.data.business_criteria]) + ); + } + // Once the user manually picks anything, stop reapplying the + // criteria-based default on subsequent renders / re-fetches. + $body.find(".jey-accounting-method").on("change", () => { + this.data.accounting_method_user_edited = true; + }); // If user has never touched the abbr field, keep it in sync with the name. // Once they edit it manually we stop auto-suggesting so their choice sticks. @@ -1044,7 +1066,18 @@ frappe.setup.SetupWizard = class JeySetupWizard { fetch_company_profile() { frappe.call({ method: "jey_wizard.etaxes.fetch_company_profile", - callback: () => { + callback: (r) => { + const m = r.message || {}; + this.data.business_criteria = (m.criteria || "").toLowerCase(); + // Heuristic: micro businesses use cash accounting, everyone + // else accrual. Skip if the user has already touched the + // select on the company step. + if (!this.data.accounting_method_user_edited && this.data.business_criteria) { + this.data.accounting_method = + this.data.business_criteria === "micro" + ? "Kassa metodu" + : "Hesablama metodu"; + } this.asan_state = "done"; this.show_current_step(); },