Auto-pick Kassa for micro entities, Hesablama otherwise

fetch_company_profile now also returns the lower-cased
criteriaOfBusinessEntity ("micro" / "small" / "medium" / "big" / etc.)
so the JS layer can react before the user reaches the company step.

Heuristic in fetch_company_profile callback:
  criteria === "micro"  → Kassa metodu
  any other criteria    → Hesablama metodu
  unknown / fetch error → static "Hesablama metodu" default stands

The auto-pick is one-shot and respectful: once the user manually
changes the select on the company step we set
accounting_method_user_edited = true, and subsequent renders /
re-fetches no longer overwrite the choice. The hint line under the
field explains where the default came from when the heuristic ran.
This commit is contained in:
Ali 2026-04-29 10:59:15 +00:00
parent f10721302e
commit 7a9c25ba35
3 changed files with 45 additions and 5 deletions

View File

@ -1 +1 @@
__version__ = "0.1.14"
__version__ = "0.1.15"

View File

@ -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()

View File

@ -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 {
<option value="Hesablama metodu">${__("Hesablama metodu")}</option>
<option value="Kassa metodu">${__("Kassa metodu")}</option>
</select>
<div style="color:#888;font-size:12px;margin-top:6px">${__("Stored in Company → Tax Policy.")}</div>
<div class="jey-accounting-hint" style="color:#888;font-size:12px;margin-top:6px">${__("Stored in Company → Tax Policy.")}</div>
</div>
`);
$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();
},