Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions erpnext/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ $.extend(erpnext.utils, {
let fiscal_year = "";
if (
frappe.boot.current_fiscal_year &&
date >= frappe.boot.current_fiscal_year[1] &&
date <= frappe.boot.current_fiscal_year[2]
(date == today ||
(date >= frappe.boot.current_fiscal_year[1] && date <= frappe.boot.current_fiscal_year[2]))
) {
if (with_dates) fiscal_year = frappe.boot.current_fiscal_year;
else fiscal_year = frappe.boot.current_fiscal_year[0];
Expand Down
28 changes: 23 additions & 5 deletions erpnext/startup/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import frappe
from frappe.defaults import get_user_default
from frappe.utils import cint
from frappe.utils import cint, getdate

from erpnext.accounts.utils import get_fiscal_years

Expand Down Expand Up @@ -56,11 +56,9 @@ def boot_session(bootinfo):
)

party_account_types = frappe.db.sql(""" select name, ifnull(account_type, '') from `tabParty Type`""")
fiscal_year = get_fiscal_years(
frappe.utils.nowdate(), company=get_user_default("company"), boolean=True
)
fiscal_year = get_current_or_nearest_fiscal_year()
if fiscal_year:
bootinfo.current_fiscal_year = fiscal_year[0]
bootinfo.current_fiscal_year = fiscal_year
bootinfo.party_account_types = frappe._dict(party_account_types)

bootinfo.sysdefaults.demo_company = frappe.db.get_single_value("Global Defaults", "demo_company")
Expand All @@ -69,6 +67,26 @@ def boot_session(bootinfo):
)


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

company = get_user_default("company")
fiscal_year = get_fiscal_years(frappe.utils.nowdate(), company=company, boolean=True)
if fiscal_year:
return fiscal_year[0]
return get_nearest_fiscal_year(company)


def get_nearest_fiscal_year(company):
today = getdate(frappe.utils.nowdate())
nearest = None
for fiscal_year in get_fiscal_years(company=company):
nearest = fiscal_year
if getdate(fiscal_year.year_start_date) <= today:
break
if not nearest:
return None
return (nearest.name, nearest.year_start_date, nearest.year_end_date)


def update_page_info(bootinfo):
bootinfo.page_info.update(
{
Expand Down
Loading