fix: Update call summary dialog
This commit is contained in:
parent
dd6b70c7cd
commit
8a178d6f30
@ -6,10 +6,10 @@ def get_contact_doc(phone_number):
|
|||||||
contacts = frappe.get_all('Contact', or_filters={
|
contacts = frappe.get_all('Contact', or_filters={
|
||||||
'phone': ['like', '%{}'.format(phone_number)],
|
'phone': ['like', '%{}'.format(phone_number)],
|
||||||
'mobile_no': ['like', '%{}'.format(phone_number)]
|
'mobile_no': ['like', '%{}'.format(phone_number)]
|
||||||
}, fields=['*'])
|
}, fields=['name'])
|
||||||
|
|
||||||
if contacts:
|
if contacts:
|
||||||
return contacts[0]
|
return frappe.get_doc(contacts[0].name)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_last_communication(phone_number, customer=None):
|
def get_last_communication(phone_number, customer=None):
|
||||||
|
@ -2,11 +2,42 @@ import frappe
|
|||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def handle_request(*args, **kwargs):
|
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())
|
incoming_phone_number = kwargs.get('CallFrom')
|
||||||
print(payload)
|
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())
|
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 {}
|
||||||
|
@ -1,42 +1,46 @@
|
|||||||
class CallSummaryDialog {
|
class CallSummaryDialog {
|
||||||
constructor(opts) {
|
constructor({ contact, call_payload, last_communication }) {
|
||||||
this.number = opts.number;
|
this.number = call_payload.CallFrom;
|
||||||
|
this.contact = contact;
|
||||||
|
this.last_communication = last_communication;
|
||||||
this.make();
|
this.make();
|
||||||
}
|
}
|
||||||
|
|
||||||
make() {
|
make() {
|
||||||
var d = new frappe.ui.Dialog({
|
this.dialog = new frappe.ui.Dialog({
|
||||||
'title': `Incoming Call: ${this.number}`,
|
'title': __(`Incoming call from ${this.contact ? this.contact.name : 'Unknown Number'}`),
|
||||||
|
'static': true,
|
||||||
|
'minimizable': true,
|
||||||
'fields': [{
|
'fields': [{
|
||||||
'fieldname': 'customer_info',
|
'fieldname': 'customer_info',
|
||||||
'fieldtype': 'HTML'
|
'fieldtype': 'HTML'
|
||||||
}, {
|
}, {
|
||||||
'fieldtype': 'Section Break'
|
'fieldtype': 'Section Break'
|
||||||
}, {
|
}, {
|
||||||
'fieldtype': 'Text',
|
'fieldtype': 'Small Text',
|
||||||
'label': "Last Communication",
|
'label': "Last Communication",
|
||||||
'fieldname': 'last_communication',
|
'fieldname': 'last_communication',
|
||||||
'default': 'This is not working please helpppp',
|
'read_only': true
|
||||||
'placeholder': __("Select or add new customer"),
|
|
||||||
'readonly': true
|
|
||||||
}, {
|
}, {
|
||||||
'fieldtype': 'Column Break'
|
'fieldtype': 'Column Break'
|
||||||
}, {
|
}, {
|
||||||
'fieldtype': 'Text',
|
'fieldtype': 'Small Text',
|
||||||
'label': 'Call Summary',
|
'label': 'Call Summary',
|
||||||
'fieldname': 'call_communication',
|
'fieldname': 'call_communication',
|
||||||
'default': 'This is not working please helpppp',
|
'default': 'This is not working please helpppp',
|
||||||
"placeholder": __("Select or add new customer")
|
"placeholder": __("Select or add new customer")
|
||||||
|
}, {
|
||||||
|
'fieldtype': 'Button',
|
||||||
|
'label': 'Submit',
|
||||||
|
'click': () => {
|
||||||
|
frappe.xcall()
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
// this.body.html(this.get_dialog_skeleton());
|
this.make_customer_contact();
|
||||||
frappe.xcall('erpnext.crm.call_summary.call_summary_utils.get_contact_doc', {
|
this.dialog.show();
|
||||||
phone_number: this.number
|
this.dialog.get_close_btn().show();
|
||||||
}).then(res => {
|
this.dialog.header.find('.indicator').removeClass('hidden').addClass('blue');
|
||||||
this.make_customer_contact(res, d.fields_dict["customer_info"].$wrapper);
|
|
||||||
// this.make_last_communication_section();
|
|
||||||
});
|
|
||||||
d.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_dialog_skeleton() {
|
get_dialog_skeleton() {
|
||||||
@ -56,16 +60,23 @@ class CallSummaryDialog {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
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('<b>Unknown Contact</b>');
|
wrapper.append('<b>Unknown Contact</b>');
|
||||||
} else {
|
} else {
|
||||||
wrapper.append(`
|
wrapper.append(`
|
||||||
<img src="${res.image}">
|
<div class="customer-info flex">
|
||||||
|
<img src="${contact.image}">
|
||||||
<div class='flex-column'>
|
<div class='flex-column'>
|
||||||
<span>${res.first_name} ${res.last_name}</span>
|
<span>${contact.first_name} ${contact.last_name}</span>
|
||||||
<span>${res.mobile_no}</span>
|
<span>${contact.mobile_no}</span>
|
||||||
<span>Customer: <b>Some Enterprise</b></span>
|
${customer_link}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
@ -91,11 +102,8 @@ class CallSummaryDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on('app_ready', function() {
|
$(document).on('app_ready', function () {
|
||||||
frappe.realtime.on('incoming_call', data => {
|
frappe.realtime.on('incoming_call', data => {
|
||||||
const number = data.CallFrom;
|
frappe.call_summary_dialog = new CallSummaryDialog(data);
|
||||||
frappe.call_summary_dialog = new CallSummaryDialog({
|
|
||||||
number
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,5 +2,6 @@
|
|||||||
img {
|
img {
|
||||||
width: auto;
|
width: auto;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user