From 50fceef0c366f1edd5ecebfbf6128480b3f26de3 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sat, 11 Nov 2023 13:35:39 +0530 Subject: [PATCH] feat: add/remove contact in deal --- crm/fcrm/doctype/crm_deal/crm_deal.py | 23 ++++++- frontend/src/pages/Deal.vue | 95 +++++++++++++++++++++++---- 2 files changed, 106 insertions(+), 12 deletions(-) diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index 3cfcf347..df1c8413 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -1,7 +1,8 @@ # Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -# import frappe +import frappe +from frappe import _ from frappe.model.document import Document @@ -17,3 +18,23 @@ class CRMDeal(Document): { "label": 'Email', "value": 'email' }, { "label": 'Mobile no', "value": 'mobile_no' }, ] + +@frappe.whitelist() +def add_contact(deal, contact): + if not frappe.has_permission("CRM Deal", "write", deal): + frappe.throw(_("Not allowed to add contact to Deal"), frappe.PermissionError) + + deal = frappe.get_cached_doc("CRM Deal", deal) + deal.append("contacts", {"contact": contact}) + deal.save() + return True + +@frappe.whitelist() +def remove_contact(deal, contact): + if not frappe.has_permission("CRM Deal", "write", deal): + frappe.throw(_("Not allowed to remove contact from Deal"), frappe.PermissionError) + + deal = frappe.get_cached_doc("CRM Deal", deal) + deal.contacts = [d for d in deal.contacts if d.contact != contact] + deal.save() + return True \ No newline at end of file diff --git a/frontend/src/pages/Deal.vue b/frontend/src/pages/Deal.vue index ae21a4c0..390fbc1a 100644 --- a/frontend/src/pages/Deal.vue +++ b/frontend/src/pages/Deal.vue @@ -102,16 +102,44 @@ :class="{ 'border-b': i !== detailSections.length - 1 }" > -
- - {{ section.label }} +
+
+ + {{ section.label }} +
+
+ + + +
-
+
+
+
+ No contacts added +
@@ -354,6 +394,7 @@ import { Avatar, Tabs, Breadcrumbs, + call, } from 'frappe-ui' import { ref, computed } from 'vue' import { useRouter } from 'vue-router' @@ -519,6 +560,38 @@ const detailSections = computed(() => { ] }) +async function addContact(value) { + let d = await call('crm.fcrm.doctype.crm_deal.crm_deal.add_contact', { + deal: props.dealId, + contact: value, + }) + if (d) { + deal.reload() + contacts.reload() + createToast({ + title: 'Contact added', + icon: 'check', + iconClasses: 'text-green-600', + }) + } +} + +async function removeContact(value) { + let d = await call('crm.fcrm.doctype.crm_deal.crm_deal.remove_contact', { + deal: props.dealId, + contact: value, + }) + if (d) { + deal.reload() + contacts.reload() + createToast({ + title: 'Contact removed', + icon: 'check', + iconClasses: 'text-green-600', + }) + } +} + const organization = computed(() => { return getOrganization(deal.data.organization) })