feat: create appoitnemnt against customer (#20457)
This commit is contained in:
parent
da9a3936e1
commit
c1312700e8
@ -13,5 +13,14 @@ frappe.ui.form.on('Appointment', {
|
|||||||
frappe.set_route("Form", "Event", frm.doc.calendar_event);
|
frappe.set_route("Form", "Event", frm.doc.calendar_event);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onload: function(frm){
|
||||||
|
frm.set_query("appointment_with", function(){
|
||||||
|
return {
|
||||||
|
filters : {
|
||||||
|
"name": ["in", ["Customer", "Lead"]]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"actions": [],
|
||||||
"autoname": "format:APMT-{customer_name}-{####}",
|
"autoname": "format:APMT-{customer_name}-{####}",
|
||||||
"creation": "2019-08-27 10:48:27.926283",
|
"creation": "2019-08-27 10:48:27.926283",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
@ -15,7 +16,8 @@
|
|||||||
"col_br_2",
|
"col_br_2",
|
||||||
"customer_details",
|
"customer_details",
|
||||||
"linked_docs_section",
|
"linked_docs_section",
|
||||||
"lead",
|
"appointment_with",
|
||||||
|
"party",
|
||||||
"col_br_3",
|
"col_br_3",
|
||||||
"calendar_event"
|
"calendar_event"
|
||||||
],
|
],
|
||||||
@ -61,12 +63,6 @@
|
|||||||
"options": "Open\nUnverified\nClosed",
|
"options": "Open\nUnverified\nClosed",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldname": "lead",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"label": "Lead",
|
|
||||||
"options": "Lead"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "calendar_event",
|
"fieldname": "calendar_event",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
@ -91,9 +87,22 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "col_br_3",
|
"fieldname": "col_br_3",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "appointment_with",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Appointment With",
|
||||||
|
"options": "DocType"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "party",
|
||||||
|
"fieldtype": "Dynamic Link",
|
||||||
|
"label": "Party",
|
||||||
|
"options": "appointment_with"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2019-10-14 15:23:54.630731",
|
"links": [],
|
||||||
|
"modified": "2020-01-28 16:16:45.447213",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "CRM",
|
"module": "CRM",
|
||||||
"name": "Appointment",
|
"name": "Appointment",
|
||||||
|
|||||||
@ -24,6 +24,14 @@ class Appointment(Document):
|
|||||||
return lead_list[0].name
|
return lead_list[0].name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def find_customer_by_email(self):
|
||||||
|
customer_list = frappe.get_list(
|
||||||
|
'Customer', filters={'email_id': self.customer_email}, ignore_permissions=True
|
||||||
|
)
|
||||||
|
if customer_list:
|
||||||
|
return customer_list[0].name
|
||||||
|
return None
|
||||||
|
|
||||||
def before_insert(self):
|
def before_insert(self):
|
||||||
number_of_appointments_in_same_slot = frappe.db.count(
|
number_of_appointments_in_same_slot = frappe.db.count(
|
||||||
'Appointment', filters={'scheduled_time': self.scheduled_time})
|
'Appointment', filters={'scheduled_time': self.scheduled_time})
|
||||||
@ -32,11 +40,18 @@ class Appointment(Document):
|
|||||||
if (number_of_appointments_in_same_slot >= number_of_agents):
|
if (number_of_appointments_in_same_slot >= number_of_agents):
|
||||||
frappe.throw('Time slot is not available')
|
frappe.throw('Time slot is not available')
|
||||||
# Link lead
|
# Link lead
|
||||||
if not self.lead:
|
if not self.party:
|
||||||
self.lead = self.find_lead_by_email()
|
lead = self.find_lead_by_email()
|
||||||
|
customer = self.find_customer_by_email()
|
||||||
|
if customer:
|
||||||
|
self.appointment_with = "Customer"
|
||||||
|
self.party = customer
|
||||||
|
else:
|
||||||
|
self.appointment_with = "Lead"
|
||||||
|
self.party = lead
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
if self.lead:
|
if self.party:
|
||||||
# Create Calendar event
|
# Create Calendar event
|
||||||
self.auto_assign()
|
self.auto_assign()
|
||||||
self.create_calendar_event()
|
self.create_calendar_event()
|
||||||
@ -89,7 +104,7 @@ class Appointment(Document):
|
|||||||
|
|
||||||
def create_lead_and_link(self):
|
def create_lead_and_link(self):
|
||||||
# Return if already linked
|
# Return if already linked
|
||||||
if self.lead:
|
if self.party:
|
||||||
return
|
return
|
||||||
lead = frappe.get_doc({
|
lead = frappe.get_doc({
|
||||||
'doctype': 'Lead',
|
'doctype': 'Lead',
|
||||||
@ -100,7 +115,7 @@ class Appointment(Document):
|
|||||||
})
|
})
|
||||||
lead.insert(ignore_permissions=True)
|
lead.insert(ignore_permissions=True)
|
||||||
# Link lead
|
# Link lead
|
||||||
self.lead = lead.name
|
self.party = lead.name
|
||||||
|
|
||||||
def auto_assign(self):
|
def auto_assign(self):
|
||||||
from frappe.desk.form.assign_to import add as add_assignemnt
|
from frappe.desk.form.assign_to import add as add_assignemnt
|
||||||
@ -129,14 +144,14 @@ class Appointment(Document):
|
|||||||
break
|
break
|
||||||
|
|
||||||
def get_assignee_from_latest_opportunity(self):
|
def get_assignee_from_latest_opportunity(self):
|
||||||
if not self.lead:
|
if not self.party:
|
||||||
return None
|
return None
|
||||||
if not frappe.db.exists('Lead', self.lead):
|
if not frappe.db.exists('Lead', self.party):
|
||||||
return None
|
return None
|
||||||
opporutnities = frappe.get_list(
|
opporutnities = frappe.get_list(
|
||||||
'Opportunity',
|
'Opportunity',
|
||||||
filters={
|
filters={
|
||||||
'party_name': self.lead,
|
'party_name': self.party,
|
||||||
},
|
},
|
||||||
ignore_permissions=True,
|
ignore_permissions=True,
|
||||||
order_by='creation desc')
|
order_by='creation desc')
|
||||||
@ -159,7 +174,7 @@ class Appointment(Document):
|
|||||||
'status': 'Open',
|
'status': 'Open',
|
||||||
'type': 'Public',
|
'type': 'Public',
|
||||||
'send_reminder': frappe.db.get_single_value('Appointment Booking Settings', 'email_reminders'),
|
'send_reminder': frappe.db.get_single_value('Appointment Booking Settings', 'email_reminders'),
|
||||||
'event_participants': [dict(reference_doctype='Lead', reference_docname=self.lead)]
|
'event_participants': [dict(reference_doctype='Lead', reference_docname=self.party)]
|
||||||
})
|
})
|
||||||
employee = _get_employee_from_user(self._assign)
|
employee = _get_employee_from_user(self._assign)
|
||||||
if employee:
|
if employee:
|
||||||
|
|||||||
@ -181,10 +181,32 @@ function setup_details_page() {
|
|||||||
navigate_to_page(2)
|
navigate_to_page(2)
|
||||||
let date_container = document.getElementsByClassName('date-span')[0];
|
let date_container = document.getElementsByClassName('date-span')[0];
|
||||||
let time_container = document.getElementsByClassName('time-span')[0];
|
let time_container = document.getElementsByClassName('time-span')[0];
|
||||||
|
setup_search_params();
|
||||||
date_container.innerHTML = moment(window.selected_date).format("MMM Do YYYY");
|
date_container.innerHTML = moment(window.selected_date).format("MMM Do YYYY");
|
||||||
time_container.innerHTML = moment(window.selected_time, "HH:mm:ss").format("LT");
|
time_container.innerHTML = moment(window.selected_time, "HH:mm:ss").format("LT");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setup_search_params() {
|
||||||
|
let search_params = new URLSearchParams(window.location.search);
|
||||||
|
let customer_name = search_params.get("name")
|
||||||
|
let customer_email = search_params.get("email")
|
||||||
|
let detail = search_params.get("details")
|
||||||
|
if (customer_name) {
|
||||||
|
let name_input = document.getElementById("customer_name");
|
||||||
|
name_input.value = customer_name;
|
||||||
|
name_input.disabled = true;
|
||||||
|
}
|
||||||
|
if(customer_email) {
|
||||||
|
let email_input = document.getElementById("customer_email");
|
||||||
|
email_input.value = customer_email;
|
||||||
|
email_input.disabled = true;
|
||||||
|
}
|
||||||
|
if(detail) {
|
||||||
|
let detail_input = document.getElementById("customer_notes");
|
||||||
|
detail_input.value = detail;
|
||||||
|
detail_input.disabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
async function submit() {
|
async function submit() {
|
||||||
let button = document.getElementById('submit-button');
|
let button = document.getElementById('submit-button');
|
||||||
button.disabled = true;
|
button.disabled = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user