Skip to content

Commit

Permalink
fix: get_activities error will fetching deleted fields
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Nov 24, 2023
1 parent 3df38f2 commit b2d2726
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crm/api/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def get_lead_activities(name):
get_docinfo('', "CRM Lead", name)
docinfo = frappe.response["docinfo"]
lead_fields_meta = frappe.get_meta("CRM Lead").fields
lead_fields = {field.fieldname: {"label": field.label, "options": field.options} for field in lead_fields_meta}

doc = frappe.db.get_values("CRM Lead", name, ["creation", "owner"])[0]
activities = [{
Expand All @@ -123,19 +124,21 @@ def get_lead_activities(name):

docinfo.versions.reverse()


for version in docinfo.versions:
data = json.loads(version.data)
if not data.get("changed"):
continue

field_option = None

if change := data.get("changed")[0]:
field_label, field_option = next(((f.label, f.options) for f in lead_fields_meta if f.fieldname == change[0]), None)
field = lead_fields.get(change[0], None)

if field_label == "Converted" or (not change[1] and not change[2]):
if not field or change[0] == "converted" or (not change[1] and not change[2]):
continue

field_label = field.get("label") or change[0]
field_option = field.get("options") or None

activity_type = "changed"
data = {
"field": change[0],
Expand Down

0 comments on commit b2d2726

Please sign in to comment.