def validate_workstation_holiday(self, schedule_date, skip_holiday_list_check=False): if not skip_holiday_list_check and (not self.holiday_list or cint(frappe.db.get_single_value("Manufacturing Settings", "allow_production_on_holidays"))): return schedule_date if schedule_date in tuple(get_holidays(self.holiday_list)): schedule_date = add_days(schedule_date, 1) self.validate_workstation_holiday(schedule_date, skip_holiday_list_check=True) return schedule_date
def mark_holidays(att_map, from_date, to_date, students_list): holiday_list = get_holiday_list() holidays = get_holidays(holiday_list) for dt in daterange(getdate(from_date), getdate(to_date)): if dt in holidays: for student in students_list: att_map.setdefault(student, frappe._dict()).setdefault(dt, "Holiday") return att_map
def get_expected_time_for(parameter, service_level, start_date_time): current_date_time = start_date_time expected_time = current_date_time start_time = end_time = None expected_time_is_set = 0 allotted_seconds = get_allotted_seconds(parameter, service_level) support_days = get_support_days(service_level) holidays = get_holidays(service_level.get("holiday_list")) weekdays = get_weekdays() while not expected_time_is_set: current_weekday = weekdays[current_date_time.weekday()] if not is_holiday(current_date_time, holidays) and current_weekday in support_days: if (getdate(current_date_time) == getdate(start_date_time) and get_time_in_timedelta(current_date_time.time()) > support_days[current_weekday].start_time): start_time = current_date_time - datetime( current_date_time.year, current_date_time.month, current_date_time.day) else: start_time = support_days[current_weekday].start_time end_time = support_days[current_weekday].end_time time_left_today = time_diff_in_seconds(end_time, start_time) # no time left for support today if time_left_today <= 0: pass elif allotted_seconds: if time_left_today >= allotted_seconds: expected_time = datetime.combine( getdate(current_date_time), get_time(start_time)) expected_time = add_to_date(expected_time, seconds=allotted_seconds) expected_time_is_set = 1 else: allotted_seconds = allotted_seconds - time_left_today if not expected_time_is_set: current_date_time = add_to_date(current_date_time, days=1) if end_time and allotted_seconds >= 86400: current_date_time = datetime.combine(getdate(current_date_time), get_time(end_time)) else: current_date_time = expected_time return current_date_time