From 57aaf34d3e97b6fa0c6c9bc7ece94eec26940e92 Mon Sep 17 00:00:00 2001 From: Rehan Ansari Date: Tue, 14 Oct 2025 23:38:17 +0530 Subject: [PATCH 1/3] fix: fiscal year overlap validation for company-specific years --- erpnext/accounts/doctype/fiscal_year/fiscal_year.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py index 13f0e5bb547..e4f935e91fb 100644 --- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py +++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py @@ -99,7 +99,7 @@ class FiscalYear(Document): ) overlap = False - if not self.get("companies") or not company_for_existing: + if not self.get("companies") and not company_for_existing: overlap = True for d in self.get("companies"): From 94ae0988549ff0e411d9157acbe84795e59708b0 Mon Sep 17 00:00:00 2001 From: Rehan Ansari Date: Wed, 15 Oct 2025 23:33:02 +0530 Subject: [PATCH 2/3] test: fiscal year overlap validation for company-specific years --- .../doctype/fiscal_year/test_fiscal_year.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py index 0f0a6837cba..999924a60eb 100644 --- a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py +++ b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py @@ -25,6 +25,35 @@ class TestFiscalYear(IntegrationTestCase): self.assertRaises(frappe.exceptions.InvalidDates, fy.insert) + def test_company_fiscal_year_overlap(self): + for name in ["_Test Global FY 2001", "_Test Company FY 2001"]: + if frappe.db.exists("Fiscal Year", name): + frappe.delete_doc("Fiscal Year", name) + + global_fy = frappe.get_doc( + { + "doctype": "Fiscal Year", + "year": "_Test Global FY 2001", + "year_start_date": "2001-04-01", + "year_end_date": "2002-03-31", + } + ) + global_fy.insert() + + company_fy = frappe.get_doc( + { + "doctype": "Fiscal Year", + "year": "_Test Company FY 2001", + "year_start_date": "2001-01-01", + "year_end_date": "2001-12-31", + "companies": [{"company": "_Test Company"}], + } + ) + + company_fy.insert() + self.assertTrue(frappe.db.exists("Fiscal Year", global_fy.name)) + self.assertTrue(frappe.db.exists("Fiscal Year", company_fy.name)) + def test_record_generator(): test_records = [ From d59e55fb08296f1258ee1ed80b514d251a53b815 Mon Sep 17 00:00:00 2001 From: rehansari26 Date: Thu, 16 Oct 2025 11:04:48 +0530 Subject: [PATCH 3/3] test: replace get_doc with new_doc in fiscal year tests --- .../doctype/fiscal_year/test_fiscal_year.py | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py index 999924a60eb..22624e270aa 100644 --- a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py +++ b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py @@ -30,25 +30,17 @@ class TestFiscalYear(IntegrationTestCase): if frappe.db.exists("Fiscal Year", name): frappe.delete_doc("Fiscal Year", name) - global_fy = frappe.get_doc( - { - "doctype": "Fiscal Year", - "year": "_Test Global FY 2001", - "year_start_date": "2001-04-01", - "year_end_date": "2002-03-31", - } - ) + global_fy = frappe.new_doc("Fiscal Year") + global_fy.year = "_Test Global FY 2001" + global_fy.year_start_date = "2001-04-01" + global_fy.year_end_date = "2002-03-31" global_fy.insert() - company_fy = frappe.get_doc( - { - "doctype": "Fiscal Year", - "year": "_Test Company FY 2001", - "year_start_date": "2001-01-01", - "year_end_date": "2001-12-31", - "companies": [{"company": "_Test Company"}], - } - ) + company_fy = frappe.new_doc("Fiscal Year") + company_fy.year = "_Test Company FY 2001" + company_fy.year_start_date = "2001-01-01" + company_fy.year_end_date = "2001-12-31" + company_fy.append("companies", {"company": "_Test Company"}) company_fy.insert() self.assertTrue(frappe.db.exists("Fiscal Year", global_fy.name))