Browse Source

Added flow for verifying emails

develop
Pranav Nachanekar 5 years ago
parent
commit
df1a5a9633
  1. 91
      erpnext/crm/doctype/appointment/appointment.py
  2. 7
      erpnext/www/book-appointment/index.py
  3. 18
      erpnext/www/book-appointment/verify/index.html
  4. 14
      erpnext/www/book-appointment/verify/index.py

91
erpnext/crm/doctype/appointment/appointment.py

@ -13,28 +13,56 @@ from frappe.desk.form.assign_to import add as add_assignemnt
class Appointment(Document):
def validate(self):
email=''
def find_lead_by_email(self,email):
lead_list = frappe.get_list('Lead', filters = {'email_id':email}, ignore_permissions = True)
if lead_list:
return lead_list[0].name
self.email = email
return None
def before_insert(self):
number_of_appointments_in_same_slot = frappe.db.count('Appointment', filters = {'scheduled_time':self.scheduled_time})
settings = frappe.get_doc('Appointment Booking Settings')
if(number_of_appointments_in_same_slot >= settings.number_of_agents):
frappe.throw('Time slot is not available')
def before_insert(self):
self.lead = _find_lead_by_email(self.lead).name
# Link lead
self.lead = self.find_lead_by_email(self.lead)
def after_insert(self):
appointment_event = frappe.get_doc({
'doctype': 'Event',
'subject': ' '.join(['Appointment with', self.customer_name]),
'starts_on': self.scheduled_time,
'status': 'Open',
'type': 'Private',
'send_reminder': frappe.db.get_single_value('Appointment Booking Settings','email_reminders'),
'event_participants': [dict(reference_doctype = "Lead", reference_docname = self.lead)]
# Auto assign
self.auto_assign()
# Check if lead was found
if(self.lead):
# Create Calendar event
self.create_calendar_event()
else:
# Send email to confirm
# frappe.sendmail(recipients=[self.email],message='https:/',subject="")
frappe.msgprint("Please check your email to confirm the appointment")
def set_verified(self,email):
# Create new lead
self.create_lead(email)
# Create calender event
self.create_calendar_event()
self.save( ignore_permissions=True )
frappe.db.commit()
def create_lead(self,email):
lead = frappe.get_doc({
'doctype':'Lead',
'lead_name':self.customer_name,
'email_id':email,
'notes':self.customer_details,
'phone':self.customer_phone_number,
})
appointment_event.insert(ignore_permissions=True)
self.calendar_event = appointment_event.name
print(lead.insert( ignore_permissions=True ))
# Link lead
self.lead = lead.name
def auto_assign(self):
available_agents = _get_agents_sorted_by_asc_workload(self.scheduled_time.date())
for agent in available_agents:
if(_check_agent_availability(agent, self.scheduled_time)):
@ -44,15 +72,27 @@ class Appointment(Document):
'name':self.name,
'assign_to':agent
})
employee = _get_employee_from_user(agent)
if employee:
calendar_event = frappe.get_doc('Event', self.calendar_event)
calendar_event.append('event_participants', dict(
reference_doctype= 'Employee',
reference_docname= employee.name))
calendar_event.save()
break
def create_calendar_event(self):
appointment_event = frappe.get_doc({
'doctype': 'Event',
'subject': ' '.join(['Appointment with', self.customer_name]),
'starts_on': self.scheduled_time,
'status': 'Open',
'type': 'Public',
'send_reminder': frappe.db.get_single_value('Appointment Booking Settings','email_reminders'),
'event_participants': [dict(reference_doctype = "Lead", reference_docname = self.lead)]
})
employee = _get_employee_from_user(self._assign)
if employee:
appointment_event.append('event_participants', dict(
reference_doctype = 'Employee',
reference_docname = employee.name))
appointment_event.insert(ignore_permissions=True)
self.calendar_event = appointment_event.name
self.save(ignore_permissions=True)
def _get_agents_sorted_by_asc_workload(date):
appointments = frappe.db.get_list('Appointment', fields='*')
agent_list = _get_agent_list_as_strings()
@ -70,13 +110,6 @@ def _get_agents_sorted_by_asc_workload(date):
return sorted_agent_list
def _find_lead_by_email(email):
lead_list = frappe.get_list('Lead', filters={'email_id':email}, ignore_permissions=True)
if lead_list:
return lead_list[0]
frappe.throw('Email ID not associated with any Lead. Please make sure to use the email address you got this mail on')
def _get_agent_list_as_strings():
agent_list_as_strings = []
agent_list = frappe.get_doc('Appointment Booking Settings').agent_list

7
erpnext/www/book-appointment/index.py

@ -111,18 +111,15 @@ def filter_timeslots(date, timeslots):
filtered_timeslots.append(timeslot)
return filtered_timeslots
def check_availabilty(timeslot, settings):
return frappe.db.count('Appointment', {'scheduled_time': timeslot}) < settings.number_of_agents
def _is_holiday(date, holiday_list):
for holiday in holiday_list.holidays:
if holiday.holiday_date == date:
return True
return False
def _get_records(start_time, end_time, settings):
records = []
for record in settings.availability_of_slots:
@ -130,17 +127,14 @@ def _get_records(start_time, end_time, settings):
records.append(record)
return records
def _deltatime_to_datetime(date, deltatime):
time = (datetime.datetime.min + deltatime).time()
return datetime.datetime.combine(date.date(), time)
def _datetime_to_deltatime(date_time):
midnight = datetime.datetime.combine(date_time.date(), datetime.time.min)
return (date_time-midnight)
def _convert_to_ist(datetime_object, timezone):
offset = datetime.timedelta(minutes=timezone)
datetime_object = datetime_object + offset
@ -148,7 +142,6 @@ def _convert_to_ist(datetime_object, timezone):
datetime_object = datetime_object - offset
return datetime_object
def _convert_to_tz(datetime_object, timezone):
offset = datetime.timedelta(minutes=timezone)
datetime_object = datetime_object - offset

18
erpnext/www/book-appointment/verify/index.html

@ -0,0 +1,18 @@
{% extends "templates/web.html" %}
{% block title %}
{{ _("Verify Email") }}
{% endblock%}
{% block page_content %}
{% if success==True %}
<div class="alert alert-success">
Your email has been verified and your appointment has been scheduled
</div>
{% else %}
<div class="alert alert-danger">
Verification failed please check the link
</div>
{% endif %}
{% endblock%}

14
erpnext/www/book-appointment/verify/index.py

@ -0,0 +1,14 @@
import frappe
@frappe.whitelist(allow_guest=True)
def get_context(context):
email = frappe.form_dict['email']
appointment_name = frappe.form_dict['appointment']
if email and appointment_name:
appointment = frappe.get_doc('Appointment',appointment_name)
appointment.set_verified(email)
context.success = True
return context
else:
print('Something not found')
context.success = False
return context
Loading…
Cancel
Save