Skip to content

fix: fall back to nearest fiscal year when today is outside all fiscal years - #57951

Closed
mihir-kandoi wants to merge 1 commit into
frappe:version-15-hotfixfrom
mihir-kandoi:fix-fiscal-year-fallback-v15
Closed

fix: fall back to nearest fiscal year when today is outside all fiscal years#57951
mihir-kandoi wants to merge 1 commit into
frappe:version-15-hotfixfrom
mihir-kandoi:fix-fiscal-year-fallback-v15

Conversation

@mihir-kandoi

Copy link
Copy Markdown
Collaborator

Fixes the Accounting workspace failing with "Start Year and End Year are mandatory" when today's date is not inside any active Fiscal Year — e.g. the last FY ended on 30 June and the next one was never created because the scheduler was down around year end, so auto_create_fiscal_year never ran. Reported in https://discuss.frappe.io/t/164081 (v15.119.0).

The standard Profit and Loss chart resolves its fiscal year filters through erpnext.utils.get_fiscal_year() in dynamic_filters_json. For today's date that helper only reads frappe.boot.current_fiscal_year, and boot skips setting it when no Fiscal Year covers today. The helper then returns "" (the server-call fallback is gated on date != today), the chart runs the Profit and Loss Statement with empty from_fiscal_year/to_fiscal_year, and the thrown error blocks the whole workspace. Budget Variance, Top Customers, Top Suppliers and the order trends charts fail the same way; fiscal year report defaults come up empty in the same state.

(The forum post blames a "non-existent erpnext.utils.get_fiscal_year" — that's the Python path; dynamic_filters_json is evaluated client side, where the helper exists but returned an empty string.)

Changes:

  • boot: when no Fiscal Year covers today, send the nearest one — the latest FY that has already started, else the earliest upcoming one.
  • erpnext.utils.get_fiscal_year: use the boot fiscal year whenever it is asked for today's fiscal year, even if today lies outside its dates. Exact lookups for other dates keep the existing server round trip and still return nothing when the date is uncovered.

The fiscal-year number cards already guard against this exact absence with their own calendar-year fallback (frappe.boot.current_fiscal_year || [...]); with boot now populated they show the nearest FY's range instead, consistent with the charts.

develop has the same gap (raise_on_missing=False in boot, same client-side guard) — I'll forward-port after review.

…l years

When the last defined Fiscal Year has ended and the next one was never
created (e.g. the scheduler was down around year end, so auto-creation
never ran), boot carried no current_fiscal_year and
erpnext.utils.get_fiscal_year() returned an empty string for today's
date with no server fallback. The standard Profit and Loss dashboard
chart then ran the Profit and Loss Statement with empty fiscal year
filters, and the thrown "Start Year and End Year are mandatory" error
blocked the whole Accounting workspace. Budget Variance, Top Customers,
Top Suppliers and the order trends charts fail the same way, and report
fiscal year defaults come up empty.

Boot now sends the nearest fiscal year (the latest one that has already
started, else the earliest upcoming one) when none covers today, and the
client helper uses the boot value whenever it is asked for today's
fiscal year. Lookups for other dates keep the exact server round trip
and still return nothing when the date is uncovered.
@github-actions github-actions Bot added the needs-tests This PR needs automated unit-tests. label Aug 10, 2026
@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The PR appears safe to merge, with only the non-blocking need to document the new public fiscal-year helper functions.

The nearest-year loop matches the descending query order for both past and upcoming fiscal years, and no behavioral failure remains; the accepted concern is limited to missing documentation for the new public helpers.

Files Needing Attention: erpnext/startup/boot.py

Fix All in Claude Code Fix All in Codex

Reviews (1): Last reviewed commit: "fix: fall back to nearest fiscal year wh..." | Re-trigger Greptile

Comment thread erpnext/startup/boot.py
)


def get_current_or_nearest_fiscal_year():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Undocumented fiscal-year fallback helpers

The new public module-level helpers lack docstrings describing their non-obvious nearest-fiscal-year selection and return shape, increasing the maintenance cost and risk of incorrect reuse.

Context Used: Guidelines for reviewing Frappe Framework applicat... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-tests This PR needs automated unit-tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant