From 9be40ee7c3e1b574164997571e66f5085c2e14ff Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 20 Apr 2016 18:09:15 +0530 Subject: [PATCH] [fixes] raise exception while deleting fiscal year if fiscal year is set as default in Global Settings and while calculating get_month_details if year_start_date not found --- erpnext/accounts/doctype/fiscal_year/fiscal_year.py | 5 +++++ erpnext/hr/doctype/process_payroll/process_payroll.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py index 9456924a87..8ff209a835 100644 --- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py +++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py @@ -40,6 +40,11 @@ class FiscalYear(Document): def on_update(self): check_duplicate_fiscal_year(self) + + def on_trash(self): + global_defaults = frappe.get_doc("Global Defaults") + if global_defaults.current_fiscal_year == self.name: + frappe.throw(_("You cannot delete Fiscal Year {0}. Fiscal Year {0} is set as default in Global Settings").format(self.name)) @frappe.whitelist() def check_duplicate_fiscal_year(doc): diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.py b/erpnext/hr/doctype/process_payroll/process_payroll.py index a71200cb57..51e3740ed6 100644 --- a/erpnext/hr/doctype/process_payroll/process_payroll.py +++ b/erpnext/hr/doctype/process_payroll/process_payroll.py @@ -206,3 +206,5 @@ def get_month_details(year, month): 'month_end_date': med, 'month_days': month_days }) + else: + frappe.throw(_("Fiscal Year {0} not found").format(year)) \ No newline at end of file