fix: get linked deals in contact
This commit is contained in:
parent
318a497886
commit
e286551bca
@ -15,6 +15,7 @@ def set_primary_email(doc):
|
||||
if len(doc.email_ids) == 1:
|
||||
doc.email_ids[0].is_primary = 1
|
||||
|
||||
|
||||
def set_primary_mobile_no(doc):
|
||||
if not doc.phone_nos:
|
||||
return
|
||||
@ -22,6 +23,43 @@ def set_primary_mobile_no(doc):
|
||||
if len(doc.phone_nos) == 1:
|
||||
doc.phone_nos[0].is_primary_mobile_no = 1
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_linked_deals(contact):
|
||||
"""Get linked deals for a contact"""
|
||||
|
||||
if not frappe.has_permission("Contact", "read", contact):
|
||||
frappe.throw("Not permitted", frappe.PermissionError)
|
||||
|
||||
deal_names = frappe.get_all(
|
||||
"CRM Contacts",
|
||||
filters={"contact": contact, "parenttype": "CRM Deal"},
|
||||
fields=["parent"],
|
||||
distinct=True,
|
||||
)
|
||||
|
||||
# get deals data
|
||||
deals = []
|
||||
for d in deal_names:
|
||||
deal = frappe.get_cached_doc(
|
||||
"CRM Deal",
|
||||
d.parent,
|
||||
fields=[
|
||||
"name",
|
||||
"organization",
|
||||
"annual_revenue",
|
||||
"status",
|
||||
"email",
|
||||
"mobile_no",
|
||||
"deal_owner",
|
||||
"modified",
|
||||
],
|
||||
)
|
||||
deals.append(deal.as_dict())
|
||||
|
||||
return deals
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_new(contact, field, value):
|
||||
"""Create new email or phone for a contact"""
|
||||
|
||||
@ -357,25 +357,12 @@ const leads = createListResource({
|
||||
auto: true,
|
||||
})
|
||||
|
||||
const deals = createListResource({
|
||||
type: 'list',
|
||||
doctype: 'CRM Deal',
|
||||
const deals = createResource({
|
||||
url: 'crm.api.contact.get_linked_deals',
|
||||
cache: ['deals', props.contactId],
|
||||
fields: [
|
||||
'name',
|
||||
'organization',
|
||||
'annual_revenue',
|
||||
'status',
|
||||
'email',
|
||||
'mobile_no',
|
||||
'deal_owner',
|
||||
'modified',
|
||||
],
|
||||
filters: {
|
||||
email: contact.value?.email_id,
|
||||
params: {
|
||||
contact: props.contactId,
|
||||
},
|
||||
orderBy: 'modified desc',
|
||||
pageLength: 20,
|
||||
auto: true,
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user