From 8a178d6f300e066a9187500f73ed058203fc7806 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Sat, 18 May 2019 16:11:29 +0530 Subject: [PATCH] fix: Update call summary dialog --- .../crm/call_summary/call_summary_utils.py | 4 +- .../crm/call_summary/exotel_call_handler.py | 41 ++++++++++-- .../js/call_popup/call_summary_dialog.js | 66 +++++++++++-------- erpnext/public/less/call_summary.less | 1 + 4 files changed, 76 insertions(+), 36 deletions(-) diff --git a/erpnext/crm/call_summary/call_summary_utils.py b/erpnext/crm/call_summary/call_summary_utils.py index 5814e2b97b..49491d5a4a 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 82c925de06..a0c3b7d5ea 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 9909b709c9..e9823eeeef 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(` - -
- ${res.first_name} ${res.last_name} - ${res.mobile_no} - Customer: Some Enterprise +
+ +
+ ${contact.first_name} ${contact.last_name} + ${contact.mobile_no} + ${customer_link} +
`); } @@ -91,11 +102,8 @@ class CallSummaryDialog { } } -$(document).on('app_ready', function() { +$(document).on('app_ready', function () { frappe.realtime.on('incoming_call', data => { - const number = data.CallFrom; - frappe.call_summary_dialog = new CallSummaryDialog({ - number - }); + frappe.call_summary_dialog = new CallSummaryDialog(data); }); }); diff --git a/erpnext/public/less/call_summary.less b/erpnext/public/less/call_summary.less index 73f6fd4f77..0ec2066105 100644 --- a/erpnext/public/less/call_summary.less +++ b/erpnext/public/less/call_summary.less @@ -2,5 +2,6 @@ img { width: auto; height: 100px; + margin-right: 15px; } } \ No newline at end of file