diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py index 45924213045..69cfe3109f5 100644 --- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py +++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py @@ -9,10 +9,6 @@ from frappe.model.document import Document from frappe.utils import add_days, add_years, cstr, getdate -class FiscalYearIncorrectDate(frappe.ValidationError): - pass - - class FiscalYear(Document): @frappe.whitelist() def set_as_default(self): @@ -53,23 +49,18 @@ class FiscalYear(Document): ) def validate_dates(self): + self.validate_from_to_dates("year_start_date", "year_end_date") if self.is_short_year: # Fiscal Year can be shorter than one year, in some jurisdictions # under certain circumstances. For example, in the USA and Germany. return - 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"), - 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"), - FiscalYearIncorrectDate, + frappe.exceptions.InvalidDates, ) def on_update(self): diff --git a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py index 6e946f74660..181406bad7c 100644 --- a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py +++ b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py @@ -7,8 +7,6 @@ import unittest import frappe from frappe.utils import now_datetime -from erpnext.accounts.doctype.fiscal_year.fiscal_year import FiscalYearIncorrectDate - test_ignore = ["Company"] @@ -26,7 +24,7 @@ class TestFiscalYear(unittest.TestCase): } ) - self.assertRaises(FiscalYearIncorrectDate, fy.insert) + self.assertRaises(frappe.exceptions.InvalidDates, fy.insert) def test_record_generator(): @@ -35,8 +33,8 @@ def test_record_generator(): "doctype": "Fiscal Year", "year": "_Test Short Fiscal Year 2011", "is_short_year": 1, - "year_end_date": "2011-04-01", - "year_start_date": "2011-12-31", + "year_start_date": "2011-04-01", + "year_end_date": "2011-12-31", } ] diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index ed46d85e3a4..b666e0d7c69 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -10,7 +10,7 @@ import re import frappe from frappe import _, throw from frappe.model.document import Document -from frappe.utils import cint, flt, getdate +from frappe.utils import cint, flt apply_on_dict = {"Item Code": "items", "Item Group": "item_groups", "Brand": "brands"} @@ -184,8 +184,7 @@ class PricingRule(Document): if self.is_cumulative and not (self.valid_from and self.valid_upto): frappe.throw(_("Valid from and valid upto fields are mandatory for the cumulative")) - if self.valid_from and self.valid_upto and getdate(self.valid_from) > getdate(self.valid_upto): - frappe.throw(_("Valid from date must be less than valid upto date")) + self.validate_from_to_dates("valid_from", "valid_upto") def validate_condition(self): if ( diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.py b/erpnext/accounts/doctype/tax_rule/tax_rule.py index 4d201292ed2..87c5e6d588e 100644 --- a/erpnext/accounts/doctype/tax_rule/tax_rule.py +++ b/erpnext/accounts/doctype/tax_rule/tax_rule.py @@ -32,7 +32,7 @@ class TaxRule(Document): def validate(self): self.validate_tax_template() - self.validate_date() + self.validate_from_to_dates("from_date", "to_date") self.validate_filters() self.validate_use_for_shopping_cart() @@ -51,10 +51,6 @@ class TaxRule(Document): if not (self.sales_tax_template or self.purchase_tax_template): frappe.throw(_("Tax Template is mandatory.")) - def validate_date(self): - if self.from_date and self.to_date and self.from_date > self.to_date: - frappe.throw(_("From Date cannot be greater than To Date")) - def validate_filters(self): filters = { "tax_type": self.tax_type,