From bf8d6ae6bf074a5282d043480e5cb8a141021557 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 20:21:46 +0530 Subject: [PATCH] feat: add option to update modified on communication recieved (backport #45307) (#45310) * feat: add option to update modified on communication recieved (#45307) (cherry picked from commit aa38895caf2748caff492c6eccb58100e1795f0c) # Conflicts: # erpnext/crm/doctype/crm_settings/crm_settings.json * chore: resolve conflict --------- Co-authored-by: Ejaaz Khan <67804911+iamejaaz@users.noreply.github.com> Co-authored-by: ruthra kumar --- .../doctype/crm_settings/crm_settings.json | 19 ++++++++++++++++--- .../crm/doctype/crm_settings/crm_settings.py | 1 + erpnext/crm/utils.py | 14 ++++++++++++++ erpnext/hooks.py | 5 ++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.json b/erpnext/crm/doctype/crm_settings/crm_settings.json index 26a07d2e859..f9dc3902c8f 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.json +++ b/erpnext/crm/doctype/crm_settings/crm_settings.json @@ -17,7 +17,9 @@ "quotation_section", "default_valid_till", "section_break_13", - "carry_forward_communication_and_comments" + "carry_forward_communication_and_comments", + "column_break_junk", + "update_timestamp_on_new_communication" ], "fields": [ { @@ -77,7 +79,7 @@ { "fieldname": "section_break_13", "fieldtype": "Section Break", - "label": "Other Settings" + "label": "Activity" }, { "default": "0", @@ -85,13 +87,24 @@ "fieldname": "carry_forward_communication_and_comments", "fieldtype": "Check", "label": "Carry Forward Communication and Comments" + }, + { + "fieldname": "column_break_junk", + "fieldtype": "Column Break" + }, + { + "default": "0", + "description": "Update the modified timestamp on new communications received in Lead & Opportunity.", + "fieldname": "update_timestamp_on_new_communication", + "fieldtype": "Check", + "label": "Update timestamp on new communication" } ], "icon": "fa fa-cog", "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2022-06-06 11:22:08.464253", + "modified": "2025-01-16 16:12:14.889455", "modified_by": "Administrator", "module": "CRM", "name": "CRM Settings", diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.py b/erpnext/crm/doctype/crm_settings/crm_settings.py index 499a6d723d3..23992043145 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.py +++ b/erpnext/crm/doctype/crm_settings/crm_settings.py @@ -20,6 +20,7 @@ class CRMSettings(Document): carry_forward_communication_and_comments: DF.Check close_opportunity_after_days: DF.Int default_valid_till: DF.Data | None + update_timestamp_on_new_communication: DF.Check # end: auto-generated types def validate(self): diff --git a/erpnext/crm/utils.py b/erpnext/crm/utils.py index c543c387c03..eb784c28ca7 100644 --- a/erpnext/crm/utils.py +++ b/erpnext/crm/utils.py @@ -84,6 +84,20 @@ def link_communications_with_prospect(communication, method): row.db_update() +def update_modified_timestamp(communication, method): + if communication.reference_doctype and communication.reference_name: + if communication.sent_or_received == "Received" and frappe.db.get_single_value( + "CRM Settings", "update_timestamp_on_new_communication" + ): + frappe.db.set_value( + dt=communication.reference_doctype, + dn=communication.reference_name, + field="modified", + val=now(), + update_modified=False, + ) + + def get_linked_prospect(reference_doctype, reference_name): prospect = None if reference_doctype == "Lead": diff --git a/erpnext/hooks.py b/erpnext/hooks.py index d5c43f5060d..653679bfb56 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -351,7 +351,10 @@ doc_events = { "erpnext.support.doctype.service_level_agreement.service_level_agreement.on_communication_update", "erpnext.support.doctype.issue.issue.set_first_response_time", ], - "after_insert": "erpnext.crm.utils.link_communications_with_prospect", + "after_insert": [ + "erpnext.crm.utils.link_communications_with_prospect", + "erpnext.crm.utils.update_modified_timestamp", + ], }, "Event": { "after_insert": "erpnext.crm.utils.link_events_with_prospect",