fix: update lead/note/call based on contact

This commit is contained in:
Shariq Ansari 2023-08-29 01:03:57 +05:30
parent 20f3c089aa
commit 7526612ffe
5 changed files with 54 additions and 15 deletions

View File

@ -14,7 +14,8 @@ class CRMLead(Document):
self.set_lead_name() self.set_lead_name()
self.set_title() self.set_title()
self.validate_email() self.validate_email()
self.validate_contact() if not self.is_new():
self.validate_contact()
def set_full_name(self): def set_full_name(self):
if self.first_name: if self.first_name:

View File

@ -84,6 +84,9 @@ def update_call_log(call_sid, status=None):
call_log.duration = call_details.duration call_log.duration = call_details.duration
call_log.start_time = get_datetime_from_timestamp(call_details.start_time) call_log.start_time = get_datetime_from_timestamp(call_details.start_time)
call_log.end_time = get_datetime_from_timestamp(call_details.end_time) call_log.end_time = get_datetime_from_timestamp(call_details.end_time)
call_log.lead = get_lead_from_number(call_log)
if call_log.note and call_log.lead:
frappe.db.set_value("CRM Note", call_log.note, "lead", call_log.lead)
call_log.flags.ignore_permissions = True call_log.flags.ignore_permissions = True
call_log.save() call_log.save()
frappe.db.commit() frappe.db.commit()
@ -138,3 +141,15 @@ def add_note_to_call_log(call_sid, note):
call_details = twilio.get_call_info(call_sid) call_details = twilio.get_call_info(call_sid)
frappe.db.set_value("CRM Call Log", call_details.parent_call_sid, "note", note) frappe.db.set_value("CRM Call Log", call_details.parent_call_sid, "note", note)
frappe.db.commit()
def get_lead_from_number(call):
"""Get lead from the given number.
"""
lead = None
if call.type == 'Outgoing':
lead = frappe.db.get_value("CRM Lead", { "mobile_no": call.get('to') })
else:
lead = frappe.db.get_value("CRM Lead", { "mobile_no": call.get('from') })
return lead

@ -1 +1 @@
Subproject commit 9167057574f2650e83360beb05ae25f0b6478211 Subproject commit 2d30e159e20274011b87fa6077613557f302ec26

View File

@ -362,6 +362,10 @@ function hangUpCall() {
onCall.value = false onCall.value = false
callStatus.value = '' callStatus.value = ''
muted.value = false muted.value = false
note.value = {
title: '',
content: '',
}
counterUp.value.stop() counterUp.value.stop()
} }
@ -375,6 +379,7 @@ function handleDisconnectedIncomingCall() {
} }
_call.value = null _call.value = null
muted.value = false muted.value = false
onCall.value = false
counterUp.value.stop() counterUp.value.stop()
} }
@ -419,6 +424,10 @@ async function makeOutgoingCall(number) {
callStatus.value = '' callStatus.value = ''
muted.value = false muted.value = false
counterUp.value.stop() counterUp.value.stop()
note.value = {
title: '',
content: '',
}
// update_call_log(conn) // update_call_log(conn)
}) })
_call.value.on('cancel', () => { _call.value.on('cancel', () => {
@ -430,6 +439,10 @@ async function makeOutgoingCall(number) {
_call.value = null _call.value = null
callStatus.value = '' callStatus.value = ''
muted.value = false muted.value = false
note.value = {
title: '',
content: '',
}
counterUp.value.stop() counterUp.value.stop()
}) })
} catch (error) { } catch (error) {
@ -452,6 +465,10 @@ function cancelCall() {
onCall.value = false onCall.value = false
callStatus.value = '' callStatus.value = ''
muted.value = false muted.value = false
note.value = {
title: '',
content: '',
}
} }
function toggleCallWindow() { function toggleCallWindow() {

View File

@ -22,7 +22,7 @@
<div class="text-sm text-gray-900">{{ callLog.doc[field.key] }}</div> <div class="text-sm text-gray-900">{{ callLog.doc[field.key] }}</div>
</div> </div>
</div> </div>
<div class="px-3 pb-1 text-base font-medium mt-3">Call note</div> <!-- <div class="px-3 pb-1 text-base font-medium mt-3">Call note</div>
<div v-if="callNote?.doc" class="flex flex-col p-3"> <div v-if="callNote?.doc" class="flex flex-col p-3">
<TextInput <TextInput
type="text" type="text"
@ -38,7 +38,7 @@
@change="(val) => (callNote.doc.content = val)" @change="(val) => (callNote.doc.content = val)"
placeholder="Type something and press enter" placeholder="Type something and press enter"
/> />
</div> </div> -->
</div> </div>
</template> </template>
@ -116,20 +116,21 @@ const details = {
], ],
} }
const callNote = computed(() => { // const callNote = computed(() => {
return createDocumentResource({ // return createDocumentResource({
doctype: 'CRM Note', // doctype: 'CRM Note',
name: callLog.doc?.note, // name: callLog.doc?.note,
auto: true, // auto: true,
setValue: {}, // setValue: {},
}) // })
}) // })
async function createLead() { async function createLead() {
let d = await call('frappe.client.insert', { let d = await call('frappe.client.insert', {
doc: { doc: {
doctype: 'CRM Lead', doctype: 'CRM Lead',
lead_name: 'Lead from call', first_name: "Lead from " + callLog.doc.from,
mobile_no: callLog.doc.from,
}, },
}) })
if (d.name) { if (d.name) {
@ -140,7 +141,12 @@ async function createLead() {
} }
async function update_note(lead) { async function update_note(lead) {
callNote.value.setValue.submit({ lead: lead }) await call('frappe.client.set_value', {
doctype: 'CRM Note',
name: callLog.doc?.note,
fieldname: 'lead',
value: lead,
})
} }
async function update_call_log(lead) { async function update_call_log(lead) {