moved validations to sepeate functions

This commit is contained in:
Pranav Nachanekar 2019-10-09 15:49:48 +05:30
parent 2c99594688
commit aa918e8528

View File

@ -8,22 +8,31 @@ from frappe import _
import datetime
from frappe.model.document import Document
class AppointmentBookingSettings(Document):
def validate(self):
# Day of week should not be repeated
list_of_days = []
date = '01/01/1970 '
format_string = "%d/%m/%Y %H:%M:%S"
min_date = '01/01/1970 '
format_string = "%d/%m/%Y %H:%M:%S"
for record in self.availability_of_slots:
list_of_days.append(record.day_of_week)
# Difference between from_time and to_time is multiple of appointment_duration
from_time = datetime.datetime.strptime(date+record.from_time, format_string)
to_time = datetime.datetime.strptime(date+record.to_time, format_string)
timedelta = to_time-from_time
def validate(self):
self.validate_availability_of_slots()
if(from_time > to_time):
frappe.throw('From Time cannot be later than To Time for '+record.day_of_week)
if timedelta.total_seconds() % (self.appointment_duration * 60):
frappe.throw('The difference between from time and To Time must be a multiple of Appointment ')
def validate_availability_of_slots(self):
for record in self.availability_of_slots:
from_time = datetime.datetime.strptime(
min_date+record.from_time, format_string)
to_time = datetime.datetime.strptime(
min_date+record.to_time, format_string)
timedelta = to_time-from_time
self.from_time_is_later_than_to_time(from_time, to_time)
self.duration_is_divisible(from_time, to_time)
def from_time_is_later_than_to_time(self, from_time, to_time):
if from_time > to_time:
err_msg = 'From Time cannot be later than To Time for '+record.day_of_week
frappe.throw(_(err_msg))
def duration_is_divisible(self, from_time, to_time):
timedelta = to_time - from_time
if timedelta.total_seconds() % (self.appointment_duration * 60):
frappe.throw(
_('The difference between from time and To Time must be a multiple of Appointmen'))