diff --git a/helpdesk/helpdesk/hooks/contact.py b/helpdesk/helpdesk/hooks/contact.py index ac8d153a1..be4671c1f 100644 --- a/helpdesk/helpdesk/hooks/contact.py +++ b/helpdesk/helpdesk/hooks/contact.py @@ -24,3 +24,15 @@ def get_list_filters(query): ) return query + +def before_insert(doc, method=None): + if doc.email_id: + domain = doc.email_id.split("@")[1] + hd_customers = frappe.get_all( + "HD Customer", filters={"domain": domain}, fields=["name"] + ) + if hd_customers: + doc.append("links", { + "link_doctype": "HD Customer", + "link_name": hd_customers[0].name + }) \ No newline at end of file diff --git a/helpdesk/hooks.py b/helpdesk/hooks.py index 1550aad39..9145c47eb 100644 --- a/helpdesk/hooks.py +++ b/helpdesk/hooks.py @@ -44,6 +44,7 @@ ], }, "Contact": { + "before_insert": "helpdesk.helpdesk.hooks.contact.before_insert", "on_trash": [ "helpdesk.helpdesk.doctype.hd_ticket.hd_ticket.update_ticket", ],