Fixed Maintenance Schedule to work wit new Holiday List
Improved code in Holiday List for speed
This commit is contained in:
parent
3427c939bd
commit
ba54a43e32
@ -4,7 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe.utils import cint, get_datetime
|
||||
from frappe.utils import cint, getdate
|
||||
from frappe import throw, _
|
||||
from frappe.model.document import Document
|
||||
|
||||
@ -59,7 +59,6 @@ class HolidayList(Document):
|
||||
|
||||
|
||||
def get_weekly_off_date_list(self, start_date, end_date):
|
||||
from frappe.utils import getdate
|
||||
start_date, end_date = getdate(start_date), getdate(end_date)
|
||||
|
||||
from dateutil import relativedelta
|
||||
@ -71,8 +70,7 @@ class HolidayList(Document):
|
||||
weekday = getattr(calendar, (self.weekly_off).upper())
|
||||
reference_date = start_date + relativedelta.relativedelta(weekday=weekday)
|
||||
|
||||
for holiday in self.get("holidays"):
|
||||
existing_date_list.append(get_datetime(holiday.holiday_date).date())
|
||||
existing_date_list = [getdate(holiday.holiday_date) for holiday in self.get("holidays")]
|
||||
|
||||
while reference_date <= end_date:
|
||||
if reference_date not in existing_date_list:
|
||||
|
@ -90,30 +90,19 @@ class MaintenanceSchedule(TransactionBase):
|
||||
return schedule_list
|
||||
|
||||
def validate_schedule_date_for_holiday_list(self, schedule_date, sales_person):
|
||||
from erpnext.accounts.utils import get_fiscal_year
|
||||
validated = False
|
||||
fy_details = ""
|
||||
|
||||
try:
|
||||
fy_details = get_fiscal_year(date=schedule_date, verbose=0)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if fy_details and fy_details[0]:
|
||||
# check holiday list in employee master
|
||||
holiday_list = frappe.db.sql_list("""select h.holiday_date from `tabEmployee` emp,
|
||||
`tabSales Person` sp, `tabHoliday` h, `tabHoliday List` hl
|
||||
where sp.name=%s and emp.name=sp.employee
|
||||
and hl.name=emp.holiday_list and
|
||||
h.parent=hl.name and
|
||||
hl.fiscal_year=%s""", (sales_person, fy_details[0]))
|
||||
where h.parent=hl.name and sp.name=%s and emp.name=sp.employee
|
||||
and hl.name=emp.holiday_list
|
||||
""", (sales_person))
|
||||
if not holiday_list:
|
||||
# check global holiday list
|
||||
holiday_list = frappe.db.sql("""select h.holiday_date from
|
||||
holiday_list = frappe.db.sql_list("""select h.holiday_date from
|
||||
`tabHoliday` h, `tabHoliday List` hl
|
||||
where h.parent=hl.name and hl.is_default = 1
|
||||
and hl.fiscal_year=%s""", fy_details[0])
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user