[fix] additional fixes for removal of Fiscal Year form Holiday List

This commit is contained in:
Anand Doshi 2016-03-11 17:16:30 +05:30
parent e2b8af16ed
commit 4284fcf2a6
14 changed files with 178 additions and 154 deletions

View File

@ -227,3 +227,16 @@ def get_employees_who_are_born_today():
from tabEmployee where day(date_of_birth) = day(%(date)s) from tabEmployee where day(date_of_birth) = day(%(date)s)
and month(date_of_birth) = month(%(date)s) and month(date_of_birth) = month(%(date)s)
and status = 'Active'""", {"date": today()}, as_dict=True) and status = 'Active'""", {"date": today()}, as_dict=True)
def get_holiday_list_for_employee(employee, raise_exception=True):
employee = frappe.db.get_value("Employee", employee, ["holiday_list", "company"], as_dict=True)
holiday_list = employee.holiday_list
if not holiday_list:
holiday_list = frappe.db.get_value("Company", employee.company, "default_holiday_list")
if not holiday_list and raise_exception:
frappe.throw(_("Please set a Holiday List for either the Employee or the Company"))
return holiday_list

View File

@ -6,32 +6,8 @@
"custom": 0, "custom": 0,
"docstatus": 0, "docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"document_type": "Setup",
"fields": [ "fields": [
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "description",
"fieldtype": "Text Editor",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Description",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "300px",
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "300px"
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -40,6 +16,7 @@
"fieldtype": "Date", "fieldtype": "Date",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Date", "label": "Date",
@ -56,6 +33,32 @@
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "description",
"fieldtype": "Text Editor",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Description",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "300px",
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "300px"
} }
], ],
"hide_heading": 0, "hide_heading": 0,
@ -67,7 +70,7 @@
"issingle": 0, "issingle": 0,
"istable": 1, "istable": 1,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-01-27 11:52:46.864792", "modified": "2016-03-11 06:39:10.913467",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Holiday", "name": "Holiday",

View File

@ -0,0 +1,14 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Holiday List', {
refresh: function(frm) {
},
from_date: function(frm) {
if (frm.doc.from_date && !frm.doc.to_date) {
var a_year_from_start = frappe.datetime.add_months(frm.doc.from_date, 12);
frm.set_value("to_date", frappe.datetime.add_days(a_year_from_start, -1));
}
}
});

View File

@ -35,30 +35,6 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "is_default",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Default",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -222,7 +198,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-03-07 05:54:39.627872", "modified": "2016-03-11 05:26:24.819829",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Holiday List", "name": "Holiday List",

View File

@ -3,8 +3,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
import json
from frappe.utils import cint, getdate from frappe.utils import cint, getdate, formatdate
from frappe import throw, _ from frappe import throw, _
from frappe.model.document import Document from frappe.model.document import Document
@ -12,8 +12,6 @@ class OverlapError(frappe.ValidationError): pass
class HolidayList(Document): class HolidayList(Document):
def validate(self): def validate(self):
self.update_default_holiday_list()
self.validate_time_period()
self.validate_days() self.validate_days()
def get_weekly_off_dates(self): def get_weekly_off_dates(self):
@ -32,31 +30,12 @@ class HolidayList(Document):
def validate_days(self): 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: if self.from_date > self.to_date:
throw(_("To Date cannot be before From Date")) throw(_("To Date cannot be before From Date"))
existing = frappe.db.sql("""select holiday_list_name, from_date, to_date from `tabHoliday List` for day in self.get("holidays"):
where if not (self.from_date <= day.holiday_date <= self.to_date):
( frappe.throw(_("The holiday on {0} is not between From Date and To Date").format(formatdate(day.holiday_date)))
(%(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): def get_weekly_off_date_list(self, start_date, end_date):
start_date, end_date = getdate(start_date), getdate(end_date) start_date, end_date = getdate(start_date), getdate(end_date)
@ -82,10 +61,6 @@ class HolidayList(Document):
def clear_table(self): def clear_table(self):
self.set('holidays', []) self.set('holidays', [])
def update_default_holiday_list(self):
frappe.db.sql("""update `tabHoliday List` set is_default = 0
where is_default = 1""")
@frappe.whitelist() @frappe.whitelist()
def get_events(start, end, filters=None): def get_events(start, end, filters=None):
"""Returns events for Gantt / Calendar view rendering. """Returns events for Gantt / Calendar view rendering.
@ -94,10 +69,27 @@ def get_events(start, end, filters=None):
:param end: End date-time. :param end: End date-time.
:param filters: Filters (JSON). :param filters: Filters (JSON).
""" """
condition = ''
values = {
"start_date": getdate(start),
"end_date": getdate(end)
}
if filters:
if isinstance(filters, basestring):
filters = json.loads(filters)
if filters.get('holiday_list'):
condition = 'and hlist.name=%(holiday_list)s'
values['holiday_list'] = filters['holiday_list']
data = frappe.db.sql("""select hlist.name, h.holiday_date, h.description
from `tabHoliday List` hlist, tabHoliday h
where h.parent = hlist.name
and h.holiday_date is not null
and h.holiday_date >= %(start_date)s
and h.holiday_date <= %(end_date)s
{condition}""".format(condition=condition),
values, as_dict=True, update={"allDay": 1})
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"
""", as_dict=True, update={"allDay": 1})
return data return data

View File

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

View File

@ -17,7 +17,6 @@
"holiday_date": "2013-02-01" "holiday_date": "2013-02-01"
} }
], ],
"holiday_list_name": "_Test Holiday List", "holiday_list_name": "_Test Holiday List"
"is_default": 1
} }
] ]

View File

@ -8,6 +8,7 @@ from frappe.utils import cint, cstr, date_diff, flt, formatdate, getdate, get_li
comma_or, get_fullname comma_or, get_fullname
from erpnext.hr.utils import set_employee_name from erpnext.hr.utils import set_employee_name
from erpnext.hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates from erpnext.hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
class LeaveDayBlockedError(frappe.ValidationError): pass class LeaveDayBlockedError(frappe.ValidationError): pass
@ -422,7 +423,7 @@ def add_block_dates(events, start, end, employee, company):
cnt+=1 cnt+=1
def add_holidays(events, start, end, employee, company): def add_holidays(events, start, end, employee, company):
applicable_holiday_list = frappe.db.get_value("Employee", employee, "holiday_list") applicable_holiday_list = get_holiday_list_for_employee(employee, company)
if not applicable_holiday_list: if not applicable_holiday_list:
return return

View File

@ -11,7 +11,7 @@ from frappe import msgprint, _
from erpnext.setup.utils import get_company_currency from erpnext.setup.utils import get_company_currency
from erpnext.hr.utils import set_employee_name from erpnext.hr.utils import set_employee_name
from erpnext.hr.doctype.process_payroll.process_payroll import get_month_details from erpnext.hr.doctype.process_payroll.process_payroll import get_month_details
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
class SalarySlip(TransactionBase): class SalarySlip(TransactionBase):
@ -108,20 +108,19 @@ class SalarySlip(TransactionBase):
return payment_days return payment_days
def get_holidays_for_employee(self, start_date, end_date): def get_holidays_for_employee(self, start_date, end_date):
holidays = frappe.db.sql("""select t1.holiday_date holiday_list = get_holiday_list_for_employee(self.employee)
from `tabHoliday` t1, tabEmployee t2 holidays = frappe.db.sql_list('''select holiday_date from `tabHoliday`
where t1.parent = t2.holiday_list and t2.name = %s where
and t1.holiday_date between %s and %s""", parent=%(holiday_list)s
(self.employee, start_date, end_date)) and holiday_date >= %(start_date)s
and holiday_date <= %(end_date)s''', {
"holiday_list": holiday_list,
"start_date": start_date,
"end_date": end_date
})
if not holidays: holidays = [cstr(i) for i in holidays]
holidays = frappe.db.sql("""select t1.holiday_date
from `tabHoliday` t1, `tabHoliday List` t2
where t1.parent = t2.name and t2.is_default = 1
and t1.holiday_date between %s and %s""",
(start_date, end_date))
holidays = [cstr(i[0]) for i in holidays]
return holidays return holidays
def calculate_lwp(self, holidays, m): def calculate_lwp(self, holidays, m):

View File

@ -16,7 +16,7 @@ class TestSalarySlip(unittest.TestCase):
make_allocation_record(leave_type="_Test Leave Type LWP") make_allocation_record(leave_type="_Test Leave Type LWP")
frappe.db.set_value("Holiday List", "_Test Holiday List", "is_default", 1) frappe.db.set_value("Company", "_Test Company", "default_holiday_list", "_Test Holiday List")
from erpnext.hr.doctype.leave_application.test_leave_application import _test_records as leave_applications from erpnext.hr.doctype.leave_application.test_leave_application import _test_records as leave_applications
la = frappe.copy_doc(leave_applications[2]) la = frappe.copy_doc(leave_applications[2])

View File

@ -254,3 +254,4 @@ erpnext.patches.v6_24.repost_valuation_rate_for_serialized_items
erpnext.patches.v6_24.set_recurring_id erpnext.patches.v6_24.set_recurring_id
erpnext.patches.v6_20x.set_compact_print erpnext.patches.v6_20x.set_compact_print
execute:frappe.delete_doc_if_exists("Web Form", "contact") #2016-03-10 execute:frappe.delete_doc_if_exists("Web Form", "contact") #2016-03-10
erpnext.patches.v6_20x.remove_fiscal_year_from_holiday_list

View File

@ -0,0 +1,17 @@
from __future__ import unicode_literals
import frappe
def execute():
default_holiday_list = frappe.db.get_value("Holiday List", {"is_default": 1})
if default_holiday_list:
for company in frappe.get_all("Company", fields=["name", "default_holiday_list"]):
if not company.default_holiday_list:
frappe.db.set_value("Company", company.name, "default_holiday_list", default_holiday_list)
fiscal_years = frappe._dict((fy.name, fy) for fy in frappe.get_all("Fiscal Year", fields=["name", "year_start_date", "year_end_date"]))
for holiday_list in frappe.get_all("Holiday List", fields=["name", "fiscal_year"]):
fy = fiscal_years[holiday_list.fiscal_year]
frappe.db.set_value("Holiday List", holiday_list.name, "from_date", fy.year_start_date)
frappe.db.set_value("Holiday List", holiday_list.name, "to_date", fy.year_end_date)

View File

@ -6,7 +6,8 @@
"default_currency": "INR", "default_currency": "INR",
"doctype": "Company", "doctype": "Company",
"domain": "Manufacturing", "domain": "Manufacturing",
"chart_of_accounts": "Standard" "chart_of_accounts": "Standard",
"default_holiday_list": "_Test Holiday List"
}, },
{ {
"abbr": "_TC1", "abbr": "_TC1",
@ -15,7 +16,8 @@
"default_currency": "USD", "default_currency": "USD",
"doctype": "Company", "doctype": "Company",
"domain": "Retail", "domain": "Retail",
"chart_of_accounts": "Standard" "chart_of_accounts": "Standard",
"default_holiday_list": "_Test Holiday List"
}, },
{ {
"abbr": "_TC2", "abbr": "_TC2",
@ -24,6 +26,7 @@
"country": "Germany", "country": "Germany",
"doctype": "Company", "doctype": "Company",
"domain": "Retail", "domain": "Retail",
"chart_of_accounts": "Standard" "chart_of_accounts": "Standard",
"default_holiday_list": "_Test Holiday List"
} }
] ]

View File

@ -9,6 +9,7 @@ from frappe.utils import add_days, getdate, cint, cstr
from frappe import throw, _ from frappe import throw, _
from erpnext.utilities.transaction_base import TransactionBase, delete_events from erpnext.utilities.transaction_base import TransactionBase, delete_events
from erpnext.stock.utils import get_valid_serial_nos from erpnext.stock.utils import get_valid_serial_nos
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
class MaintenanceSchedule(TransactionBase): class MaintenanceSchedule(TransactionBase):
def generate_schedule(self): def generate_schedule(self):
@ -92,22 +93,19 @@ class MaintenanceSchedule(TransactionBase):
def validate_schedule_date_for_holiday_list(self, schedule_date, sales_person): def validate_schedule_date_for_holiday_list(self, schedule_date, sales_person):
validated = False validated = False
# check holiday list in employee master employee = frappe.db.get_value("Sales Person", sales_person, "employee")
holiday_list = frappe.db.sql_list("""select h.holiday_date from `tabEmployee` emp, holiday_list = get_holiday_list_for_employee(employee)
`tabSales Person` sp, `tabHoliday` h, `tabHoliday List` hl holidays = frappe.db.sql_list('''select holiday_date from `tabHoliday` where parent=%s''', holiday_list)
where h.parent=hl.name and sp.name=%s and emp.name=sp.employee
and hl.name=emp.holiday_list if not validated and holidays:
""", (sales_person))
if not holiday_list: # max iterations = len(holidays)
# check global holiday list for i in xrange(len(holidays)):
holiday_list = frappe.db.sql_list("""select h.holiday_date from if schedule_date in holidays:
`tabHoliday` h, `tabHoliday List` hl
where h.parent=hl.name and hl.is_default = 1""")
if not validated and holiday_list:
if schedule_date in holiday_list:
schedule_date = add_days(schedule_date, -1) schedule_date = add_days(schedule_date, -1)
else: else:
validated = True validated = True
break
return schedule_date return schedule_date