Some checks failed
Frontend / Unit Tests & Coverage (push) Has been skipped
Regenerate POT file (translatable strings) / Regenerate POT file (develop) (push) Failing after 1m13s
Regenerate POT file (translatable strings) / Regenerate POT file (main-hotfix) (push) Failing after 6s
Server / Tests (frappe ${{ matrix.frappe-branch }}) (push) Has been skipped
Server / Resolve frappe matrix (push) Failing after 1s
Frontend / Lint (push) Failing after 1s
Frontend / Production Build (push) Failing after 1s
Server / Coverage Wrap Up (push) Has been skipped
Frontend / Coverage Wrap Up (push) Has been skipped
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import frappe
|
|
|
|
# CRM doctype -> frontend list route. Records live at /crm/<route>/<name>.
|
|
CRM_ROUTES = {
|
|
"CRM Lead": "leads",
|
|
"CRM Deal": "deals",
|
|
}
|
|
|
|
|
|
def before_insert(doc, method=None):
|
|
"""Point CRM notification emails at the CRM UI instead of the Desk form.
|
|
|
|
Notification Log's email builder uses `doc.link` when set, otherwise it
|
|
falls back to a Desk (`/app/...`) form URL. CRM users often have Desk
|
|
access restricted, so build a CRM frontend link for CRM documents.
|
|
See https://github.com/frappe/crm/issues/705.
|
|
"""
|
|
if doc.link:
|
|
return
|
|
|
|
route = get_crm_route(doc.document_type, doc.document_name)
|
|
if route:
|
|
doc.link = frappe.utils.get_url(route)
|
|
|
|
|
|
def get_crm_route(doctype, name):
|
|
"""Frontend path for a CRM record, or None for non-CRM documents.
|
|
|
|
Tasks have no standalone page in the CRM UI, so link to their parent
|
|
Lead/Deal's Tasks tab, mirroring the in-app notification behaviour.
|
|
"""
|
|
if not name:
|
|
return None
|
|
|
|
suffix = ""
|
|
if doctype == "CRM Task":
|
|
parent = frappe.db.get_value(
|
|
"CRM Task", name, ["reference_doctype", "reference_docname"], as_dict=True
|
|
)
|
|
if not parent or not parent.reference_docname:
|
|
return None
|
|
doctype, name = parent.reference_doctype, parent.reference_docname
|
|
suffix = "#tasks"
|
|
|
|
list_route = CRM_ROUTES.get(doctype)
|
|
if not list_route:
|
|
return None
|
|
|
|
return f"/crm/{list_route}/{name}{suffix}"
|