diff --git a/crm/fcrm/doctype/crm_lead/api.py b/crm/fcrm/doctype/crm_lead/api.py index 9f9167e8..7895ac1e 100644 --- a/crm/fcrm/doctype/crm_lead/api.py +++ b/crm/fcrm/doctype/crm_lead/api.py @@ -29,21 +29,28 @@ def get_activities(name): docinfo = frappe.response["docinfo"] lead_fields_meta = frappe.get_meta("CRM Lead").fields - doc = frappe.get_doc("CRM Lead", name, fields=["creation", "owner"]) + doc = frappe.db.get_values("CRM Lead", name, ["creation", "owner", "created_as_deal"])[0] + created_as_deal = doc[2] + is_lead = False if created_as_deal else True activities = [{ "activity_type": "creation", - "creation": doc.creation, - "owner": doc.owner, - "data": "created this lead", + "creation": doc[0], + "owner": doc[1], + "data": "created this " + ("deal" if created_as_deal else "lead"), + "is_lead": is_lead, }] + docinfo.versions.reverse() + for version in docinfo.versions: data = json.loads(version.data) if not data.get("changed"): continue if change := data.get("changed")[0]: - activity_type = "changed" field_label = next((f.label for f in lead_fields_meta if f.fieldname == change[0]), None) + activity_type = "changed" + if field_label == "Lead Owner" and (created_as_deal or not is_lead): + field_label = "Deal Owner" data = { "field": change[0], "field_label": field_label, @@ -59,6 +66,9 @@ def get_activities(name): "field_label": field_label, "value": change[2], } + if field_label == "Is Deal" and change[2] and is_lead: + activity_type = "deal" + is_lead = False elif change[1] and not change[2]: activity_type = "removed" data = { @@ -72,6 +82,7 @@ def get_activities(name): "creation": version.creation, "owner": version.owner, "data": data, + "is_lead": is_lead, } activities.append(activity) @@ -89,6 +100,7 @@ def get_activities(name): "bcc": communication.bcc, "read_by_recipient": communication.read_by_recipient, }, + "is_lead": is_lead, } activities.append(activity) diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.json b/crm/fcrm/doctype/crm_lead/crm_lead.json index 23e66072..2c774ba4 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.json +++ b/crm/fcrm/doctype/crm_lead/crm_lead.json @@ -14,6 +14,7 @@ "middle_name", "last_name", "is_deal", + "created_as_deal", "column_break_izjs", "lead_name", "gender", @@ -251,12 +252,19 @@ { "fieldname": "section_break_jyxr", "fieldtype": "Section Break" + }, + { + "default": "0", + "fieldname": "created_as_deal", + "fieldtype": "Check", + "hidden": 1, + "label": "Created as Deal" } ], "image_field": "image", "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-25 19:21:22.778067", + "modified": "2023-09-27 18:54:18.196159", "modified_by": "Administrator", "module": "FCRM", "name": "CRM Lead", diff --git a/frontend/src/components/Activities.vue b/frontend/src/components/Activities.vue index 28ad4caf..618fe3a5 100644 --- a/frontend/src/components/Activities.vue +++ b/frontend/src/components/Activities.vue @@ -448,6 +448,7 @@ import PhoneIcon from '@/components/Icons/PhoneIcon.vue' import NoteIcon from '@/components/Icons/NoteIcon.vue' import DurationIcon from '@/components/Icons/DurationIcon.vue' import PlayIcon from '@/components/Icons/PlayIcon.vue' +import LeadsIcon from '@/components/Icons/LeadsIcon.vue' import DealsIcon from '@/components/Icons/DealsIcon.vue' import DotIcon from '@/components/Icons/DotIcon.vue' import EmailAtIcon from '@/components/Icons/EmailAtIcon.vue' @@ -582,7 +583,7 @@ const activities = computed(() => { return notes.data } activities.forEach((activity) => { - activity.icon = timelineIcon(activity.activity_type) + activity.icon = timelineIcon(activity.activity_type, activity.is_lead) if ( activity.activity_type == 'incoming_call' || @@ -611,6 +612,10 @@ function update_activities_details(activity) { if (activity.activity_type == 'creation') { activity.type = activity.data + } else if (activity.activity_type == 'deal') { + activity.type = 'converted the lead to this deal' + activity.data.field_label = '' + activity.data.value = '' } else if (activity.activity_type == 'added') { activity.type = 'added' activity.value = 'as' @@ -644,10 +649,13 @@ const emptyTextIcon = computed(() => { return h(icon, { class: 'text-gray-500' }) }) -function timelineIcon(activity_type) { +function timelineIcon(activity_type, is_lead) { let icon switch (activity_type) { case 'creation': + icon = is_lead ? LeadsIcon : DealsIcon + break + case 'deal': icon = DealsIcon break case 'communication': diff --git a/frontend/src/components/Icons/LeadsIcon.vue b/frontend/src/components/Icons/LeadsIcon.vue index e44bbb86..8d0c37d2 100644 --- a/frontend/src/components/Icons/LeadsIcon.vue +++ b/frontend/src/components/Icons/LeadsIcon.vue @@ -1,21 +1,16 @@ diff --git a/frontend/src/pages/Deals.vue b/frontend/src/pages/Deals.vue index 509d3da1..41989a63 100644 --- a/frontend/src/pages/Deals.vue +++ b/frontend/src/pages/Deals.vue @@ -258,6 +258,8 @@ let newDeal = reactive({ email: '', mobile_no: '', lead_owner: getUser().email, + is_deal: 1, + created_as_deal: 1, }) const createLead = createResource({ @@ -284,9 +286,9 @@ function createNewDeal(close) { }, onSuccess(data) { router.push({ - name: 'Lead', + name: 'Deal', params: { - leadId: data.name, + dealId: data.name, }, }) }, diff --git a/frontend/src/pages/Lead.vue b/frontend/src/pages/Lead.vue index 1d6ab549..7f5f95de 100644 --- a/frontend/src/pages/Lead.vue +++ b/frontend/src/pages/Lead.vue @@ -378,6 +378,9 @@ function updateLead(fieldname, value) { }, auto: true, onSuccess: () => { + if (fieldname == 'is_deal') { + router.push({ name: 'Deal', params: { dealId: lead.data.name } }) + } lead.reload() contacts.reload() reload.value = true @@ -575,7 +578,6 @@ function convertToDeal() { lead.data.status = 'Qualified' lead.data.is_deal = 1 updateLead('is_deal', 1) - router.push({ name: 'Deal', params: { dealId: lead.data.name } }) } function updateAssignedAgent(email) {