refator: Rename files and move code

This commit is contained in:
Suraj Shetty 2019-05-21 07:57:06 +05:30
parent 8a178d6f30
commit 863b93c32d
5 changed files with 86 additions and 86 deletions

View File

@ -1,18 +0,0 @@
import frappe
@frappe.whitelist()
def get_contact_doc(phone_number):
phone_number = phone_number[-10:]
contacts = frappe.get_all('Contact', or_filters={
'phone': ['like', '%{}'.format(phone_number)],
'mobile_no': ['like', '%{}'.format(phone_number)]
}, fields=['name'])
if contacts:
return frappe.get_doc(contacts[0].name)
@frappe.whitelist()
def get_last_communication(phone_number, customer=None):
# find last communication through phone_number
# find last issues, opportunity, lead
pass

View File

@ -1,43 +0,0 @@
import frappe
@frappe.whitelist(allow_guest=True)
def handle_request(*args, **kwargs):
# r = frappe.request
# print(r.args.to_dict(), args, kwargs)
incoming_phone_number = kwargs.get('CallFrom')
contact = get_contact_doc(incoming_phone_number)
last_communication = get_last_communication(incoming_phone_number, contact)
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 {}

View File

@ -0,0 +1,20 @@
import frappe
def get_document_with_phone_number(number):
# finds contacts and leads
number = number[-10:]
number_filter = {
'phone': ['like', '%{}'.format(number)],
'mobile_no': ['like', '%{}'.format(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)

View File

@ -0,0 +1,41 @@
import frappe
from erpnext.crm.doctype.utils import get_document_with_phone_number
@frappe.whitelist(allow_guest=True)
def handle_incoming_call(*args, **kwargs):
incoming_phone_number = kwargs.get('CallFrom')
contact = get_document_with_phone_number(incoming_phone_number)
last_communication = get_last_communication(incoming_phone_number, contact)
call_log = create_call_log(kwargs)
data = {
'contact': contact,
'call_payload': kwargs,
'last_communication': last_communication,
'call_log': call_log
}
frappe.publish_realtime('incoming_call', data)
def get_last_communication(phone_number, contact):
# frappe.get_all('Communication', filter={})
return {}
def create_call_log(call_payload):
communication = frappe.new_doc('Communication')
communication.subject = frappe._('Call from {}').format(call_payload.get("CallFrom"))
communication.communication_medium = 'Phone'
communication.send_email = 0
communication.phone_no = call_payload.get("CallFrom")
communication.comment_type = 'Info'
communication.communication_type = 'Communication'
communication.status = 'Open'
communication.sent_or_received = 'Received'
communication.content = 'call_payload'
communication.communication_date = call_payload.get('StartTime')
# communication.sid = call_payload.get('CallSid')
# communication.exophone = call_payload.get('CallTo')
# communication.call_receiver = call_payload.get('DialWhomNumber')
communication.save(ignore_permissions=True)
return communication

View File

@ -1,4 +1,4 @@
class CallSummaryDialog {
class CallPopup {
constructor({ contact, call_payload, last_communication }) {
this.number = call_payload.CallFrom;
this.contact = contact;
@ -8,7 +8,6 @@ class CallSummaryDialog {
make() {
this.dialog = new frappe.ui.Dialog({
'title': __(`Incoming call from ${this.contact ? this.contact.name : 'Unknown Number'}`),
'static': true,
'minimizable': true,
'fields': [{
@ -27,40 +26,21 @@ class CallSummaryDialog {
'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.dialog.get_value();
}
}]
});
this.set_call_status();
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() {
return `
<div class="call-summary-body">
<div class="customer-info flex">
</div>
<div class="flex">
<div class="last-communication"></div>
<div class="call-summary"></div>
</div>
<hr>
<div class="flex">
<div class="section-right"></div>
<div class="section-left"></div>
</div>
</div>
`;
}
make_customer_contact() {
const wrapper = this.dialog.fields_dict["customer_info"].$wrapper;
const contact = this.contact;
@ -100,10 +80,30 @@ class CallSummaryDialog {
make_summary_section() {
//
}
set_call_status(status) {
let title = '';
if (status === 'incoming') {
if (this.contact) {
title = __('Incoming call from {0}', [this.contact.name]);
} else {
title = __('Incoming call from unknown number');
}
}
this.dialog.set_title(title);
}
update(data) {
// pass
}
}
$(document).on('app_ready', function () {
frappe.realtime.on('incoming_call', data => {
frappe.call_summary_dialog = new CallSummaryDialog(data);
frappe.realtime.on('call_update', data => {
if (!erpnext.call_popup) {
erpnext.call_popup = new CallPopup(data);
} else {
erpnext.call_popup.update(data);
}
});
});