Added validation for fiscal year
This commit is contained in:
parent
4275c30059
commit
26b646f8a3
@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
import math
|
import math
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import (flt, getdate, get_first_day, get_last_day,
|
from frappe.utils import (flt, getdate, get_first_day, get_last_day, date_diff,
|
||||||
add_months, add_days, formatdate, cint)
|
add_months, add_days, formatdate, cint)
|
||||||
|
|
||||||
def get_period_list(from_fiscal_year, to_fiscal_year, periodicity):
|
def get_period_list(from_fiscal_year, to_fiscal_year, periodicity):
|
||||||
@ -25,6 +25,8 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity):
|
|||||||
year_start_date = get_first_day(getdate(from_fy_start_end_date[0]))
|
year_start_date = get_first_day(getdate(from_fy_start_end_date[0]))
|
||||||
year_end_date = getdate(to_fy_start_end_date[1])
|
year_end_date = getdate(to_fy_start_end_date[1])
|
||||||
|
|
||||||
|
validate_fiscal_year(year_start_date, year_end_date)
|
||||||
|
|
||||||
months_to_add = {
|
months_to_add = {
|
||||||
"Yearly": 12,
|
"Yearly": 12,
|
||||||
"Half-Yearly": 6,
|
"Half-Yearly": 6,
|
||||||
@ -35,9 +37,9 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity):
|
|||||||
period_list = []
|
period_list = []
|
||||||
|
|
||||||
start_date = year_start_date
|
start_date = year_start_date
|
||||||
months = flt(get_months(year_start_date, year_end_date))
|
months = get_months(year_start_date, year_end_date)
|
||||||
|
|
||||||
for i in xrange(cint(math.ceil(months / flt(months_to_add)))):
|
for i in xrange(months / months_to_add):
|
||||||
period = frappe._dict({
|
period = frappe._dict({
|
||||||
"from_date": start_date
|
"from_date": start_date
|
||||||
})
|
})
|
||||||
@ -83,6 +85,10 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity):
|
|||||||
|
|
||||||
return period_list
|
return period_list
|
||||||
|
|
||||||
|
def validate_fiscal_year(start_date, end_date):
|
||||||
|
if date_diff(end_date, start_date) <= 0:
|
||||||
|
frappe.throw(_("End Year cannot be before Start Year"))
|
||||||
|
|
||||||
def get_months(start_date, end_date):
|
def get_months(start_date, end_date):
|
||||||
diff = (12 * end_date.year + end_date.month) - (12 * start_date.year + start_date.month)
|
diff = (12 * end_date.year + end_date.month) - (12 * start_date.year + start_date.month)
|
||||||
return diff + 1
|
return diff + 1
|
||||||
|
@ -70,7 +70,7 @@ function get_filters(){
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"from_fiscal_year",
|
"fieldname":"from_fiscal_year",
|
||||||
"label": __("Fiscal Year"),
|
"label": __("Start Year"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Fiscal Year",
|
"options": "Fiscal Year",
|
||||||
"default": frappe.defaults.get_user_default("fiscal_year"),
|
"default": frappe.defaults.get_user_default("fiscal_year"),
|
||||||
@ -78,7 +78,7 @@ function get_filters(){
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"to_fiscal_year",
|
"fieldname":"to_fiscal_year",
|
||||||
"label": __("Fiscal Year"),
|
"label": __("End Year"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Fiscal Year",
|
"options": "Fiscal Year",
|
||||||
"default": frappe.defaults.get_user_default("fiscal_year"),
|
"default": frappe.defaults.get_user_default("fiscal_year"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user