diff --git a/crm/fcrm/doctype/crm_lead/api.py b/crm/fcrm/doctype/crm_lead/api.py index aceb65d4..9f9167e8 100644 --- a/crm/fcrm/doctype/crm_lead/api.py +++ b/crm/fcrm/doctype/crm_lead/api.py @@ -93,5 +93,39 @@ def get_activities(name): activities.append(activity) activities.sort(key=lambda x: x["creation"], reverse=True) + activities = handle_multiple_versions(activities) - return activities \ No newline at end of file + return activities + +def handle_multiple_versions(versions): + activities = [] + grouped_versions = [] + old_version = None + for version in versions: + is_version = version["activity_type"] in ["changed", "added", "removed"] + if not is_version: + activities.append(version) + if not old_version: + old_version = version + if is_version: grouped_versions.append(version) + continue + if is_version and old_version.get("owner") and version["owner"] == old_version["owner"]: + grouped_versions.append(version) + else: + if grouped_versions: + activities.append(parse_grouped_versions(grouped_versions)) + grouped_versions = [] + if is_version: grouped_versions.append(version) + old_version = version + if version == versions[-1] and grouped_versions: + activities.append(parse_grouped_versions(grouped_versions)) + + return activities + +def parse_grouped_versions(versions): + version = versions[0] + if len(versions) == 1: + return version + other_versions = versions[1:] + version["other_versions"] = other_versions + return version \ No newline at end of file diff --git a/frontend/src/components/Activities.vue b/frontend/src/components/Activities.vue index bdea3ba4..28ad4caf 100644 --- a/frontend/src/components/Activities.vue +++ b/frontend/src/components/Activities.vue @@ -170,8 +170,13 @@
-
+
{{ @@ -346,6 +351,60 @@
+
+
+ {{ activity.type }} + + {{ activity.data.field_label }} + + {{ activity.value }} + + {{ activity.data.old_value }} + + to + + {{ activity.data.value }} + +
+ +
+ + {{ timeAgo(activity.creation) }} + +
+
+
+ +
@@ -415,7 +474,7 @@ import { createListResource, call, } from 'frappe-ui' -import { ref, computed, h, defineModel, markRaw } from 'vue' +import { ref, computed, h, defineModel, markRaw, watch } from 'vue' const { getUser } = usersStore() const { getContact } = contactsStore() @@ -425,13 +484,10 @@ const props = defineProps({ type: String, default: 'Activity', }, - activities: { - type: Array, - default: [], - }, }) const lead = defineModel() +const reload = defineModel('reload') const versions = createResource({ url: 'crm.fcrm.doctype.crm_lead.api.get_activities', @@ -535,28 +591,39 @@ const activities = computed(() => { ) return - activity.owner_name = getUser(activity.owner).full_name - activity.type = '' - activity.value = '' - activity.to = '' + update_activities_details(activity) - if (activity.activity_type == 'creation') { - activity.type = activity.data - } else if (activity.activity_type == 'added') { - activity.type = 'added' - activity.value = 'value as' - } else if (activity.activity_type == 'removed') { - activity.type = 'removed' - activity.value = 'value' - } else if (activity.activity_type == 'changed') { - activity.type = 'changed' - activity.value = 'value from' - activity.to = 'to' + if (activity.other_versions) { + activity.show_others = false + activity.other_versions.forEach((other_version) => { + update_activities_details(other_version) + }) } }) return activities }) +function update_activities_details(activity) { + activity.owner_name = getUser(activity.owner).full_name + activity.type = '' + activity.value = '' + activity.to = '' + + if (activity.activity_type == 'creation') { + activity.type = activity.data + } else if (activity.activity_type == 'added') { + activity.type = 'added' + activity.value = 'as' + } else if (activity.activity_type == 'removed') { + activity.type = 'removed' + activity.value = 'value' + } else if (activity.activity_type == 'changed') { + activity.type = 'changed' + activity.value = 'from' + activity.to = 'to' + } +} + const emptyText = computed(() => { let text = 'No emails communications' if (props.title == 'Calls') { @@ -645,6 +712,13 @@ async function updateNote(note) { } } } + +watch(reload, (value) => { + if (value) { + versions.reload() + reload.value = false + } +})