fix: test case for fiscal year (#16516)

This commit is contained in:
rohitwaghchaure 2019-01-29 16:24:53 +05:30 committed by Sagar Vora
parent bad36ef3ef
commit a95ed44d3d
2 changed files with 10 additions and 4 deletions

View File

@ -9,6 +9,8 @@ from dateutil.relativedelta import relativedelta
from frappe.model.document import Document from frappe.model.document import Document
class FiscalYearIncorrectDate(frappe.ValidationError): pass
class FiscalYear(Document): class FiscalYear(Document):
def set_as_default(self): def set_as_default(self):
frappe.db.set_value("Global Defaults", None, "current_fiscal_year", self.name) frappe.db.set_value("Global Defaults", None, "current_fiscal_year", self.name)
@ -35,12 +37,14 @@ class FiscalYear(Document):
def validate_dates(self): def validate_dates(self):
if getdate(self.year_start_date) > getdate(self.year_end_date): 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) date = getdate(self.year_start_date) + relativedelta(years=1) - relativedelta(days=1)
if getdate(self.year_end_date) != date: 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): def on_update(self):
check_duplicate_fiscal_year(self) check_duplicate_fiscal_year(self)

View File

@ -5,6 +5,8 @@ from __future__ import unicode_literals
import frappe, unittest import frappe, unittest
from erpnext.accounts.doctype.fiscal_year.fiscal_year import FiscalYearIncorrectDate
test_records = frappe.get_test_records('Fiscal Year') test_records = frappe.get_test_records('Fiscal Year')
test_ignore = ["Company"] test_ignore = ["Company"]
@ -12,12 +14,12 @@ class TestFiscalYear(unittest.TestCase):
def test_extra_year(self): def test_extra_year(self):
if frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2000"): if frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2000"):
frappe.delete_doc("Fiscal Year", "_Test Fiscal Year 2000") frappe.delete_doc("Fiscal Year", "_Test Fiscal Year 2000")
fy = frappe.get_doc({ fy = frappe.get_doc({
"doctype": "Fiscal Year", "doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2000", "year": "_Test Fiscal Year 2000",
"year_end_date": "2002-12-31", "year_end_date": "2002-12-31",
"year_start_date": "2000-04-01" "year_start_date": "2000-04-01"
}) })
fy.insert()
self.assertEqual(fy.year_end_date, '2001-03-31')
self.assertRaises(FiscalYearIncorrectDate, fy.insert)