fix: store status change log in lead & deal on status change

This commit is contained in:
Shariq Ansari 2024-01-06 14:11:03 +05:30
parent 33478641cb
commit e24953e0e5
5 changed files with 57 additions and 6 deletions

View File

@ -42,7 +42,9 @@
"response_by",
"column_break_hpvj",
"first_response_time",
"first_responded_on"
"first_responded_on",
"log_tab",
"status_change_log"
],
"fields": [
{
@ -251,11 +253,22 @@
"fieldtype": "Data",
"label": "Phone",
"options": "Phone"
},
{
"fieldname": "log_tab",
"fieldtype": "Tab Break",
"label": "Log"
},
{
"fieldname": "status_change_log",
"fieldtype": "Table",
"label": "Status Change Log",
"options": "CRM Status Change Log"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-01-05 16:10:59.595577",
"modified": "2024-01-06 14:05:52.669699",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Deal",

View File

@ -8,6 +8,7 @@ from frappe.desk.form.assign_to import add as assign
from frappe.model.document import Document
from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
from crm.fcrm.doctype.crm_status_change_log.crm_status_change_log import add_status_change_log
class CRMDeal(Document):
@ -20,6 +21,8 @@ class CRMDeal(Document):
self.update_organization()
if self.deal_owner and not self.is_new():
self.assign_agent(self.deal_owner)
if self.has_value_changed("status"):
add_status_change_log(self)
def after_insert(self):
if self.deal_owner:

View File

@ -46,7 +46,9 @@
"response_by",
"column_break_pweh",
"first_response_time",
"first_responded_on"
"first_responded_on",
"log_tab",
"status_change_log"
],
"fields": [
{
@ -84,7 +86,7 @@
"options": "Gender"
},
{
"default": "Open",
"default": "New",
"fieldname": "status",
"fieldtype": "Link",
"in_list_view": 1,
@ -273,12 +275,24 @@
"fieldtype": "Link",
"label": "Territory",
"options": "CRM Territory"
},
{
"fieldname": "log_tab",
"fieldtype": "Tab Break",
"label": "Log",
"read_only": 1
},
{
"fieldname": "status_change_log",
"fieldtype": "Table",
"label": "Status Change Log",
"options": "CRM Status Change Log"
}
],
"image_field": "image",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-01-04 21:34:32.388456",
"modified": "2024-01-06 13:33:54.744542",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Lead",

View File

@ -9,6 +9,7 @@ from frappe.model.document import Document
from frappe.utils import has_gravatar, validate_email_address
from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
from crm.fcrm.doctype.crm_status_change_log.crm_status_change_log import add_status_change_log
class CRMLead(Document):
@ -22,6 +23,8 @@ class CRMLead(Document):
self.validate_email()
if self.lead_owner and not self.is_new():
self.assign_agent(self.lead_owner)
if self.has_value_changed("status"):
add_status_change_log(self)
def after_insert(self):
if self.lead_owner:

View File

@ -1,9 +1,27 @@
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
import frappe
from datetime import datetime
from frappe.model.document import Document
class CRMStatusChangeLog(Document):
pass
def add_status_change_log(doc):
if not doc.is_new():
last_status_change = doc.status_change_log[-1]
last_status_change.to = doc.status
last_status_change.to_date = datetime.now()
last_status_change.log_owner = frappe.session.user
last_status_change.duration = (last_status_change.to_date - last_status_change.from_date).total_seconds()
doc.append("status_change_log", {
"from": doc.status,
"to": "",
"from_date": datetime.now(),
"to_date": "",
"log_owner": frappe.session.user,
})