Removed Fiscal Year from Holiday List and Calendar

This commit is contained in:
Valmik Jangla 2016-03-07 18:41:05 +05:30 committed by Anand Doshi
parent 58fc9037b3
commit 3085186182
3 changed files with 85 additions and 51 deletions

View File

@ -17,6 +17,7 @@
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Holiday List Name",
@ -26,6 +27,7 @@
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
@ -41,6 +43,7 @@
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Default",
@ -48,6 +51,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -59,20 +63,45 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "fiscal_year",
"fieldtype": "Link",
"fieldname": "from_date",
"fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 1,
"in_list_view": 1,
"label": "Fiscal Year",
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "From Date",
"length": 0,
"no_copy": 0,
"oldfieldname": "fiscal_year",
"oldfieldtype": "Link",
"options": "Fiscal Year",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "to_date",
"fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "To Date",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
@ -88,6 +117,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Weekly Off",
@ -96,6 +126,7 @@
"options": "\nSunday\nMonday\nTuesday\nWednesday\nThursday\nFriday\nSaturday",
"permlevel": 0,
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 1,
"reqd": 0,
@ -111,6 +142,7 @@
"fieldtype": "Button",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Get Weekly Off Dates",
@ -119,6 +151,7 @@
"options": "get_weekly_off_dates",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -134,6 +167,7 @@
"fieldtype": "Table",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Holidays",
@ -144,6 +178,7 @@
"options": "Holiday",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -159,6 +194,7 @@
"fieldtype": "Button",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Clear Table",
@ -167,6 +203,7 @@
"options": "clear_table",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -185,7 +222,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2015-11-16 06:29:47.519087",
"modified": "2016-03-07 05:54:39.627872",
"modified_by": "Administrator",
"module": "HR",
"name": "Holiday List",

View File

@ -5,20 +5,21 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cint
from frappe.model.naming import make_autoname
from frappe import throw, _
from frappe.model.document import Document
class OverlapError(frappe.ValidationError): pass
class HolidayList(Document):
def validate(self):
self.update_default_holiday_list()
self.validate_time_period()
self.validate_days()
def get_weekly_off_dates(self):
self.validate_values()
self.validate_days()
yr_start_date, yr_end_date = get_fy_start_end_dates(self.fiscal_year)
date_list = self.get_weekly_off_date_list(yr_start_date, yr_end_date)
self.validate_weekly_days()
date_list = self.get_weekly_off_date_list(self.from_date, self.to_date)
last_idx = max([cint(d.idx) for d in self.get("holidays")] or [0,])
for i, d in enumerate(date_list):
ch = self.append('holidays', {})
@ -27,19 +28,44 @@ class HolidayList(Document):
ch.idx = last_idx + i + 1
def validate_values(self):
if not self.fiscal_year:
throw(_("Please select Fiscal Year"))
if not self.weekly_off:
throw(_("Please select weekly off day"))
def validate_days(self):
def validate_weekly_days(self):
for day in self.get("holidays"):
if (self.weekly_off or "").upper() == (day.description or "").upper():
frappe.throw("Records already exist for mentioned weekly off")
def get_weekly_off_date_list(self, year_start_date, year_end_date):
def validate_days(self):
for day in self.get("holidays"):
if not self.from_date <= day.holiday_date <= self.to_date:
frappe.throw("Date not between From Date and To Date")
def validate_time_period(self):
if self.from_date > self.to_date:
throw(_("To Date cannot be before From Date"))
existing = frappe.db.sql("""select holiday_list_name, from_date, to_date from `tabHoliday List`
where
(
(%(from_date)s > from_date and %(from_date)s < to_date) or
(%(to_date)s > from_date and %(to_date)s < to_date) or
(%(from_date)s <= from_date and %(to_date)s >= to_date))
and name!=%(name)s""",
{
"from_date": self.from_date,
"to_date": self.to_date,
"name": self.holiday_list_name
}, as_dict=True)
if existing:
frappe.throw(_("This Time Period conflicts with {0} ({1} to {2})").format(existing[0].holiday_list_name,
existing[0].from_date, existing[0].to_date, OverlapError))
def get_weekly_off_date_list(self, start_date, end_date):
from frappe.utils import getdate
year_start_date, year_end_date = getdate(year_start_date), getdate(year_end_date)
year_start_date, year_end_date = getdate(start_date), getdate(end_date)
from dateutil import relativedelta
from datetime import timedelta
@ -60,40 +86,20 @@ class HolidayList(Document):
def update_default_holiday_list(self):
frappe.db.sql("""update `tabHoliday List` set is_default = 0
where is_default = 1 and fiscal_year = %s""", (self.fiscal_year,))
where is_default = 1""")
@frappe.whitelist()
def get_events(start, end, filters=None):
import json
"""Returns events for Gantt / Calendar view rendering.
:param start: Start date-time.
:param end: End date-time.
:param filters: Filters (JSON).
"""
from frappe.desk.calendar import get_event_conditions
conditions = get_event_conditions("Holiday List", filters)
fiscal_year = None
if filters:
fiscal_year = json.loads(filters).get("fiscal_year")
if not fiscal_year:
fiscal_year = frappe.db.get_value("Global Defaults", None, "current_fiscal_year")
yr_start_date, yr_end_date = get_fy_start_end_dates(fiscal_year)
data = frappe.db.sql("""select hl.name, hld.holiday_date, hld.description
from `tabHoliday List` hl, tabHoliday hld
where hld.parent = hl.name
and (ifnull(hld.holiday_date, "0000-00-00") != "0000-00-00"
and hld.holiday_date between %(start)s and %(end)s)
{conditions}""".format(conditions=conditions), {
"start": yr_start_date,
"end": yr_end_date
}, as_dict=True, update={"allDay": 1})
and ifnull(hld.holiday_date, "0000-00-00") != "0000-00-00"
""", as_dict=True, update={"allDay": 1})
return data
def get_fy_start_end_dates(fiscal_year):
return frappe.db.get_value("Fiscal Year", fiscal_year, ["year_start_date", "year_end_date"])

View File

@ -9,14 +9,5 @@ frappe.views.calendar["Holiday List"] = {
"title": "description",
"allDay": "allDay"
},
filters: [
{
"fieldtype": "Link",
"fieldname": "fiscal_year",
"options": "Fiscal Year",
"label": __("Fiscal Year"),
"default": frappe.defaults.get_user_default("fiscal_year")
}
],
get_events_method: "erpnext.hr.doctype.holiday_list.holiday_list.get_events"
}