fix: store status change log in lead & deal on status change
This commit is contained in:
parent
33478641cb
commit
e24953e0e5
@ -42,7 +42,9 @@
|
|||||||
"response_by",
|
"response_by",
|
||||||
"column_break_hpvj",
|
"column_break_hpvj",
|
||||||
"first_response_time",
|
"first_response_time",
|
||||||
"first_responded_on"
|
"first_responded_on",
|
||||||
|
"log_tab",
|
||||||
|
"status_change_log"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@ -251,11 +253,22 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Phone",
|
"label": "Phone",
|
||||||
"options": "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,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-01-05 16:10:59.595577",
|
"modified": "2024-01-06 14:05:52.669699",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Deal",
|
"name": "CRM Deal",
|
||||||
|
|||||||
@ -8,6 +8,7 @@ from frappe.desk.form.assign_to import add as assign
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
|
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):
|
class CRMDeal(Document):
|
||||||
@ -20,6 +21,8 @@ class CRMDeal(Document):
|
|||||||
self.update_organization()
|
self.update_organization()
|
||||||
if self.deal_owner and not self.is_new():
|
if self.deal_owner and not self.is_new():
|
||||||
self.assign_agent(self.deal_owner)
|
self.assign_agent(self.deal_owner)
|
||||||
|
if self.has_value_changed("status"):
|
||||||
|
add_status_change_log(self)
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
if self.deal_owner:
|
if self.deal_owner:
|
||||||
|
|||||||
@ -46,7 +46,9 @@
|
|||||||
"response_by",
|
"response_by",
|
||||||
"column_break_pweh",
|
"column_break_pweh",
|
||||||
"first_response_time",
|
"first_response_time",
|
||||||
"first_responded_on"
|
"first_responded_on",
|
||||||
|
"log_tab",
|
||||||
|
"status_change_log"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@ -84,7 +86,7 @@
|
|||||||
"options": "Gender"
|
"options": "Gender"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "Open",
|
"default": "New",
|
||||||
"fieldname": "status",
|
"fieldname": "status",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@ -273,12 +275,24 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Territory",
|
"label": "Territory",
|
||||||
"options": "CRM 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",
|
"image_field": "image",
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-01-04 21:34:32.388456",
|
"modified": "2024-01-06 13:33:54.744542",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Lead",
|
"name": "CRM Lead",
|
||||||
|
|||||||
@ -9,6 +9,7 @@ from frappe.model.document import Document
|
|||||||
|
|
||||||
from frappe.utils import has_gravatar, validate_email_address
|
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_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):
|
class CRMLead(Document):
|
||||||
@ -22,6 +23,8 @@ class CRMLead(Document):
|
|||||||
self.validate_email()
|
self.validate_email()
|
||||||
if self.lead_owner and not self.is_new():
|
if self.lead_owner and not self.is_new():
|
||||||
self.assign_agent(self.lead_owner)
|
self.assign_agent(self.lead_owner)
|
||||||
|
if self.has_value_changed("status"):
|
||||||
|
add_status_change_log(self)
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
if self.lead_owner:
|
if self.lead_owner:
|
||||||
|
|||||||
@ -1,9 +1,27 @@
|
|||||||
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
# import frappe
|
import frappe
|
||||||
|
from datetime import datetime
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
class CRMStatusChangeLog(Document):
|
class CRMStatusChangeLog(Document):
|
||||||
pass
|
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,
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user