Skip to content

Commit

Permalink
Merge pull request #52 from shariquerik/status-change-log
Browse files Browse the repository at this point in the history
feat: Add status change log in Lead/Deal
  • Loading branch information
shariquerik authored Jan 6, 2024
2 parents 91ed8c6 + e24953e commit 43f0b01
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 5 deletions.
17 changes: 15 additions & 2 deletions crm/fcrm/doctype/crm_deal/crm_deal.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"response_by",
"column_break_hpvj",
"first_response_time",
"first_responded_on"
"first_responded_on",
"log_tab",
"status_change_log"
],
"fields": [
{
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions crm/fcrm/doctype/crm_deal/crm_deal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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):
Expand All @@ -20,6 +21,8 @@ def validate(self):
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:
Expand Down
20 changes: 17 additions & 3 deletions crm/fcrm/doctype/crm_lead/crm_lead.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
"response_by",
"column_break_pweh",
"first_response_time",
"first_responded_on"
"first_responded_on",
"log_tab",
"status_change_log"
],
"fields": [
{
Expand Down Expand Up @@ -84,7 +86,7 @@
"options": "Gender"
},
{
"default": "Open",
"default": "New",
"fieldname": "status",
"fieldtype": "Link",
"in_list_view": 1,
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions crm/fcrm/doctype/crm_lead/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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):
Expand All @@ -22,6 +23,8 @@ def validate(self):
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:
Expand Down
Empty file.
78 changes: 78 additions & 0 deletions crm/fcrm/doctype/crm_status_change_log/crm_status_change_log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2024-01-06 13:15:31.392201",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"from",
"to",
"from_date",
"to_date",
"column_break_mwmz",
"duration",
"last_status_change_log",
"log_owner"
],
"fields": [
{
"fieldname": "from",
"fieldtype": "Data",
"in_list_view": 1,
"label": "From"
},
{
"fieldname": "from_date",
"fieldtype": "Datetime",
"in_list_view": 1,
"label": "From Date"
},
{
"fieldname": "duration",
"fieldtype": "Duration",
"in_list_view": 1,
"label": "Duration"
},
{
"fieldname": "column_break_mwmz",
"fieldtype": "Column Break"
},
{
"fieldname": "to",
"fieldtype": "Data",
"in_list_view": 1,
"label": "To"
},
{
"fieldname": "to_date",
"fieldtype": "Datetime",
"in_list_view": 1,
"label": "To Date"
},
{
"fieldname": "last_status_change_log",
"fieldtype": "Link",
"label": "Last Status Change Log",
"options": "CRM Status Change Log"
},
{
"fieldname": "log_owner",
"fieldtype": "Link",
"label": "Owner",
"options": "User"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-01-06 13:26:40.597277",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Status Change Log",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
27 changes: 27 additions & 0 deletions crm/fcrm/doctype/crm_status_change_log/crm_status_change_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

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,
})

0 comments on commit 43f0b01

Please sign in to comment.