From 66586093e8ab23472daabc260d34b87fb202449b Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sat, 12 Oct 2024 15:01:57 +0530 Subject: [PATCH] fix: move lead whatsapp chat to deal on convertion --- crm/api/whatsapp.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/crm/api/whatsapp.py b/crm/api/whatsapp.py index 1a0f52fd2..a38c11949 100644 --- a/crm/api/whatsapp.py +++ b/crm/api/whatsapp.py @@ -103,7 +103,41 @@ def is_whatsapp_installed(): def get_whatsapp_messages(reference_doctype, reference_name): if not frappe.db.exists("DocType", "WhatsApp Message"): return [] - messages = frappe.get_all( + messages = [] + + if reference_doctype == 'CRM Deal': + lead = frappe.db.get_value(reference_doctype, reference_name, 'lead') + if lead: + messages = frappe.get_all( + "WhatsApp Message", + filters={ + "reference_doctype": "CRM Lead", + "reference_name": lead, + }, + fields=[ + "name", + "type", + "to", + "from", + "content_type", + "message_type", + "attach", + "template", + "use_template", + "message_id", + "is_reply", + "reply_to_message_id", + "creation", + "message", + "status", + "reference_doctype", + "reference_name", + "template_parameters", + "template_header_parameters", + ], + ) + + messages += frappe.get_all( "WhatsApp Message", filters={ "reference_doctype": reference_doctype,