fix: use get_doc to get lead/deal data
This commit is contained in:
parent
3fc92ef724
commit
63fa14cc62
@ -1,38 +1,19 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
|
||||||
|
|
||||||
from crm.api.doc import get_fields_meta, get_assigned_users
|
from crm.api.doc import get_assigned_users, get_fields_meta
|
||||||
from crm.fcrm.doctype.crm_form_script.crm_form_script import get_form_script
|
from crm.fcrm.doctype.crm_form_script.crm_form_script import get_form_script
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_deal(name):
|
def get_deal(name):
|
||||||
Deal = frappe.qb.DocType("CRM Deal")
|
deal = frappe.get_doc("CRM Deal", name).as_dict()
|
||||||
|
|
||||||
query = (
|
deal["fields_meta"] = get_fields_meta("CRM Deal")
|
||||||
frappe.qb.from_(Deal)
|
deal["_form_script"] = get_form_script("CRM Deal")
|
||||||
.select("*")
|
|
||||||
.where(Deal.name == name)
|
|
||||||
.limit(1)
|
|
||||||
)
|
|
||||||
|
|
||||||
deal = query.run(as_dict=True)
|
|
||||||
if not len(deal):
|
|
||||||
frappe.throw(_("Deal not found"), frappe.DoesNotExistError)
|
|
||||||
deal = deal.pop()
|
|
||||||
|
|
||||||
|
|
||||||
deal["contacts"] = frappe.get_all(
|
|
||||||
"CRM Contacts",
|
|
||||||
filters={"parenttype": "CRM Deal", "parent": deal.name},
|
|
||||||
fields=["contact", "is_primary"],
|
|
||||||
)
|
|
||||||
|
|
||||||
deal["doctype"] = "CRM Deal"
|
|
||||||
deal["fields_meta"] = get_fields_meta("CRM Deal")
|
|
||||||
deal["_form_script"] = get_form_script('CRM Deal')
|
|
||||||
deal["_assign"] = get_assigned_users("CRM Deal", deal.name, deal.owner)
|
deal["_assign"] = get_assigned_users("CRM Deal", deal.name, deal.owner)
|
||||||
return deal
|
return deal
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_deal_contacts(name):
|
def get_deal_contacts(name):
|
||||||
contacts = frappe.get_all(
|
contacts = frappe.get_all(
|
||||||
@ -44,16 +25,19 @@ def get_deal_contacts(name):
|
|||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
is_primary = contact.is_primary
|
is_primary = contact.is_primary
|
||||||
contact = frappe.get_doc("Contact", contact.contact).as_dict()
|
contact = frappe.get_doc("Contact", contact.contact).as_dict()
|
||||||
|
|
||||||
def get_primary_email(contact):
|
def get_primary_email(contact):
|
||||||
for email in contact.email_ids:
|
for email in contact.email_ids:
|
||||||
if email.is_primary:
|
if email.is_primary:
|
||||||
return email.email_id
|
return email.email_id
|
||||||
return contact.email_ids[0].email_id if contact.email_ids else ""
|
return contact.email_ids[0].email_id if contact.email_ids else ""
|
||||||
|
|
||||||
def get_primary_mobile_no(contact):
|
def get_primary_mobile_no(contact):
|
||||||
for phone in contact.phone_nos:
|
for phone in contact.phone_nos:
|
||||||
if phone.is_primary:
|
if phone.is_primary:
|
||||||
return phone.phone
|
return phone.phone
|
||||||
return contact.phone_nos[0].phone if contact.phone_nos else ""
|
return contact.phone_nos[0].phone if contact.phone_nos else ""
|
||||||
|
|
||||||
_contact = {
|
_contact = {
|
||||||
"name": contact.name,
|
"name": contact.name,
|
||||||
"image": contact.image,
|
"image": contact.image,
|
||||||
@ -63,4 +47,4 @@ def get_deal_contacts(name):
|
|||||||
"is_primary": is_primary,
|
"is_primary": is_primary,
|
||||||
}
|
}
|
||||||
deal_contacts.append(_contact)
|
deal_contacts.append(_contact)
|
||||||
return deal_contacts
|
return deal_contacts
|
||||||
|
|||||||
@ -1,22 +1,14 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
|
||||||
|
|
||||||
from crm.api.doc import get_fields_meta, get_assigned_users
|
from crm.api.doc import get_assigned_users, get_fields_meta
|
||||||
from crm.fcrm.doctype.crm_form_script.crm_form_script import get_form_script
|
from crm.fcrm.doctype.crm_form_script.crm_form_script import get_form_script
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_lead(name):
|
def get_lead(name):
|
||||||
Lead = frappe.qb.DocType("CRM Lead")
|
lead = frappe.get_doc("CRM Lead", name).as_dict()
|
||||||
|
|
||||||
query = frappe.qb.from_(Lead).select("*").where(Lead.name == name).limit(1)
|
|
||||||
|
|
||||||
lead = query.run(as_dict=True)
|
|
||||||
if not len(lead):
|
|
||||||
frappe.throw(_("Lead not found"), frappe.DoesNotExistError)
|
|
||||||
lead = lead.pop()
|
|
||||||
|
|
||||||
lead["doctype"] = "CRM Lead"
|
|
||||||
lead["fields_meta"] = get_fields_meta("CRM Lead")
|
lead["fields_meta"] = get_fields_meta("CRM Lead")
|
||||||
lead["_form_script"] = get_form_script('CRM Lead')
|
lead["_form_script"] = get_form_script("CRM Lead")
|
||||||
lead["_assign"] = get_assigned_users("CRM Lead", lead.name, lead.owner)
|
lead["_assign"] = get_assigned_users("CRM Lead", lead.name, lead.owner)
|
||||||
return lead
|
return lead
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user