diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.json b/crm/fcrm/doctype/crm_deal/crm_deal.json index 94d3345b..96c5f22f 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.json +++ b/crm/fcrm/doctype/crm_deal/crm_deal.json @@ -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", diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index 71ae96e3..21d5cd08 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -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: diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.json b/crm/fcrm/doctype/crm_lead/crm_lead.json index 3090a4ae..e86d4200 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.json +++ b/crm/fcrm/doctype/crm_lead/crm_lead.json @@ -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", diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.py b/crm/fcrm/doctype/crm_lead/crm_lead.py index ed080a5a..7b8af194 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.py +++ b/crm/fcrm/doctype/crm_lead/crm_lead.py @@ -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: diff --git a/crm/fcrm/doctype/crm_status_change_log/crm_status_change_log.py b/crm/fcrm/doctype/crm_status_change_log/crm_status_change_log.py index 56d1d91d..4752b6b8 100644 --- a/crm/fcrm/doctype/crm_status_change_log/crm_status_change_log.py +++ b/crm/fcrm/doctype/crm_status_change_log/crm_status_change_log.py @@ -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, + }) \ No newline at end of file