fix: test case for fiscal year (#16516)
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
index 6bb71b6..d80bc7f 100644
--- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
+++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
@@ -9,6 +9,8 @@
from frappe.model.document import Document
+class FiscalYearIncorrectDate(frappe.ValidationError): pass
+
class FiscalYear(Document):
def set_as_default(self):
frappe.db.set_value("Global Defaults", None, "current_fiscal_year", self.name)
@@ -35,12 +37,14 @@
def validate_dates(self):
if getdate(self.year_start_date) > getdate(self.year_end_date):
- frappe.throw(_("Fiscal Year Start Date should be one year earlier than Fiscal Year End Date"))
+ frappe.throw(_("Fiscal Year Start Date should be one year earlier than Fiscal Year End Date"),
+ FiscalYearIncorrectDate)
date = getdate(self.year_start_date) + relativedelta(years=1) - relativedelta(days=1)
if getdate(self.year_end_date) != date:
- frappe.throw(_("Fiscal Year End Date should be one year after Fiscal Year Start Date"))
+ frappe.throw(_("Fiscal Year End Date should be one year after Fiscal Year Start Date"),
+ FiscalYearIncorrectDate)
def on_update(self):
check_duplicate_fiscal_year(self)
diff --git a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
index 5f90bb3..f7b7782 100644
--- a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
+++ b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
@@ -5,6 +5,8 @@
import frappe, unittest
+from erpnext.accounts.doctype.fiscal_year.fiscal_year import FiscalYearIncorrectDate
+
test_records = frappe.get_test_records('Fiscal Year')
test_ignore = ["Company"]
@@ -12,12 +14,12 @@
def test_extra_year(self):
if frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2000"):
frappe.delete_doc("Fiscal Year", "_Test Fiscal Year 2000")
+
fy = frappe.get_doc({
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2000",
"year_end_date": "2002-12-31",
"year_start_date": "2000-04-01"
})
- fy.insert()
- self.assertEqual(fy.year_end_date, '2001-03-31')
+ self.assertRaises(FiscalYearIncorrectDate, fy.insert)