moved validations to sepeate functions
This commit is contained in:
parent
2c99594688
commit
aa918e8528
@ -8,22 +8,31 @@ from frappe import _
|
|||||||
import datetime
|
import datetime
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
class AppointmentBookingSettings(Document):
|
class AppointmentBookingSettings(Document):
|
||||||
def validate(self):
|
min_date = '01/01/1970 '
|
||||||
# Day of week should not be repeated
|
|
||||||
list_of_days = []
|
|
||||||
date = '01/01/1970 '
|
|
||||||
format_string = "%d/%m/%Y %H:%M:%S"
|
format_string = "%d/%m/%Y %H:%M:%S"
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
self.validate_availability_of_slots()
|
||||||
|
|
||||||
|
def validate_availability_of_slots(self):
|
||||||
for record in self.availability_of_slots:
|
for record in self.availability_of_slots:
|
||||||
list_of_days.append(record.day_of_week)
|
from_time = datetime.datetime.strptime(
|
||||||
# Difference between from_time and to_time is multiple of appointment_duration
|
min_date+record.from_time, format_string)
|
||||||
from_time = datetime.datetime.strptime(date+record.from_time, format_string)
|
to_time = datetime.datetime.strptime(
|
||||||
to_time = datetime.datetime.strptime(date+record.to_time, format_string)
|
min_date+record.to_time, format_string)
|
||||||
timedelta = to_time-from_time
|
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)
|
||||||
|
|
||||||
if(from_time > to_time):
|
def from_time_is_later_than_to_time(self, from_time, to_time):
|
||||||
frappe.throw('From Time cannot be later than To Time for '+record.day_of_week)
|
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):
|
if timedelta.total_seconds() % (self.appointment_duration * 60):
|
||||||
frappe.throw('The difference between from time and To Time must be a multiple of Appointment ')
|
frappe.throw(
|
||||||
|
_('The difference between from time and To Time must be a multiple of Appointmen'))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user