diff --git a/erpnext/crm/call_summary/call_summary_utils.py b/erpnext/crm/call_summary/call_summary_utils.py
index 5814e2b97b1..49491d5a4a5 100644
--- a/erpnext/crm/call_summary/call_summary_utils.py
+++ b/erpnext/crm/call_summary/call_summary_utils.py
@@ -6,10 +6,10 @@ def get_contact_doc(phone_number):
contacts = frappe.get_all('Contact', or_filters={
'phone': ['like', '%{}'.format(phone_number)],
'mobile_no': ['like', '%{}'.format(phone_number)]
- }, fields=['*'])
+ }, fields=['name'])
if contacts:
- return contacts[0]
+ return frappe.get_doc(contacts[0].name)
@frappe.whitelist()
def get_last_communication(phone_number, customer=None):
diff --git a/erpnext/crm/call_summary/exotel_call_handler.py b/erpnext/crm/call_summary/exotel_call_handler.py
index 82c925de064..a0c3b7d5eaf 100644
--- a/erpnext/crm/call_summary/exotel_call_handler.py
+++ b/erpnext/crm/call_summary/exotel_call_handler.py
@@ -2,11 +2,42 @@ import frappe
@frappe.whitelist(allow_guest=True)
def handle_request(*args, **kwargs):
- r = frappe.request
+ # r = frappe.request
- payload = r.get_data()
+ # print(r.args.to_dict(), args, kwargs)
- print(r.args.to_dict())
- print(payload)
+ incoming_phone_number = kwargs.get('CallFrom')
+ contact = get_contact_doc(incoming_phone_number)
+ last_communication = get_last_communication(incoming_phone_number, contact)
- frappe.publish_realtime('incoming_call', r.args.to_dict())
\ No newline at end of file
+ data = {
+ 'contact': contact,
+ 'call_payload': kwargs,
+ 'last_communication': last_communication
+ }
+
+ frappe.publish_realtime('incoming_call', data)
+
+
+def get_contact_doc(phone_number):
+ phone_number = phone_number[-10:]
+ number_filter = {
+ 'phone': ['like', '%{}'.format(phone_number)],
+ 'mobile_no': ['like', '%{}'.format(phone_number)]
+ }
+ contacts = frappe.get_all('Contact', or_filters=number_filter,
+ fields=['name'], limit=1)
+
+ if contacts:
+ return frappe.get_doc('Contact', contacts[0].name)
+
+ leads = frappe.get_all('Leads', or_filters=number_filter,
+ fields=['name'], limit=1)
+
+ if leads:
+ return frappe.get_doc('Lead', leads[0].name)
+
+
+def get_last_communication(phone_number, contact):
+ # frappe.get_all('Communication', filter={})
+ return {}
diff --git a/erpnext/public/js/call_popup/call_summary_dialog.js b/erpnext/public/js/call_popup/call_summary_dialog.js
index 9909b709c91..e9823eeeefe 100644
--- a/erpnext/public/js/call_popup/call_summary_dialog.js
+++ b/erpnext/public/js/call_popup/call_summary_dialog.js
@@ -1,42 +1,46 @@
class CallSummaryDialog {
- constructor(opts) {
- this.number = opts.number;
+ constructor({ contact, call_payload, last_communication }) {
+ this.number = call_payload.CallFrom;
+ this.contact = contact;
+ this.last_communication = last_communication;
this.make();
}
make() {
- var d = new frappe.ui.Dialog({
- 'title': `Incoming Call: ${this.number}`,
+ this.dialog = new frappe.ui.Dialog({
+ 'title': __(`Incoming call from ${this.contact ? this.contact.name : 'Unknown Number'}`),
+ 'static': true,
+ 'minimizable': true,
'fields': [{
'fieldname': 'customer_info',
'fieldtype': 'HTML'
}, {
'fieldtype': 'Section Break'
}, {
- 'fieldtype': 'Text',
+ 'fieldtype': 'Small Text',
'label': "Last Communication",
'fieldname': 'last_communication',
- 'default': 'This is not working please helpppp',
- 'placeholder': __("Select or add new customer"),
- 'readonly': true
+ 'read_only': true
}, {
'fieldtype': 'Column Break'
}, {
- 'fieldtype': 'Text',
+ 'fieldtype': 'Small Text',
'label': 'Call Summary',
'fieldname': 'call_communication',
'default': 'This is not working please helpppp',
"placeholder": __("Select or add new customer")
+ }, {
+ 'fieldtype': 'Button',
+ 'label': 'Submit',
+ 'click': () => {
+ frappe.xcall()
+ }
}]
});
- // this.body.html(this.get_dialog_skeleton());
- frappe.xcall('erpnext.crm.call_summary.call_summary_utils.get_contact_doc', {
- phone_number: this.number
- }).then(res => {
- this.make_customer_contact(res, d.fields_dict["customer_info"].$wrapper);
- // this.make_last_communication_section();
- });
- d.show();
+ this.make_customer_contact();
+ this.dialog.show();
+ this.dialog.get_close_btn().show();
+ this.dialog.header.find('.indicator').removeClass('hidden').addClass('blue');
}
get_dialog_skeleton() {
@@ -56,16 +60,23 @@ class CallSummaryDialog {
`;
}
- make_customer_contact(res, wrapper) {
- if (!res) {
+
+ make_customer_contact() {
+ const wrapper = this.dialog.fields_dict["customer_info"].$wrapper;
+ const contact = this.contact;
+ const customer = this.contact.links ? this.contact.links[0] : null;
+ const customer_link = customer ? frappe.utils.get_form_link(customer.link_doctype, customer.link_name, true): '';
+ if (!contact) {
wrapper.append('Unknown Contact');
} else {
wrapper.append(`
-
-