Skip to content

Commit

Permalink
fix: accommodate for changed orderby statement
Browse files Browse the repository at this point in the history
(cherry picked from commit 87df7ff)
  • Loading branch information
GursheenK authored and mergify[bot] committed Feb 22, 2024
1 parent afc87a4 commit 6d25ba9
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions erpnext/accounts/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from frappe.contacts.doctype.address.address import get_company_address, get_default_address
from frappe.core.doctype.user_permission.user_permission import get_permitted_documents
from frappe.model.utils import get_fetch_values
from frappe.query_builder.functions import Abs, Date, Sum
from frappe.query_builder.functions import Abs, Count, Date, Sum
from frappe.utils import (
add_days,
add_months,
Expand Down Expand Up @@ -784,34 +784,37 @@ def get_timeline_data(doctype, name):
from frappe.desk.form.load import get_communication_data

out = {}
fields = "creation, count(*)"
after = add_years(None, -1).strftime("%Y-%m-%d")
group_by = "group by Date(creation)"

data = get_communication_data(
doctype,
name,
after=after,
group_by="group by creation",
fields="C.creation as creation, count(C.name)",
group_by="group by communication_date",
fields="C.communication_date as communication_date, count(C.name)",
as_dict=False,
)

# fetch and append data from Activity Log
data += frappe.db.sql(
"""select {fields}
from `tabActivity Log`
where (reference_doctype=%(doctype)s and reference_name=%(name)s)
or (timeline_doctype in (%(doctype)s) and timeline_name=%(name)s)
or (reference_doctype in ("Quotation", "Opportunity") and timeline_name=%(name)s)
and status!='Success' and creation > {after}
{group_by} order by creation desc
""".format(
fields=fields, group_by=group_by, after=after
),
{"doctype": doctype, "name": name},
as_dict=False,
)
activity_log = frappe.qb.DocType("Activity Log")
data += (
frappe.qb.from_(activity_log)
.select(activity_log.communication_date, Count(activity_log.name))
.where(
(
((activity_log.reference_doctype == doctype) & (activity_log.reference_name == name))
| ((activity_log.timeline_doctype == doctype) & (activity_log.timeline_name == name))
| (
(activity_log.reference_doctype.isin(["Quotation", "Opportunity"]))
& (activity_log.timeline_name == name)
)
)
& (activity_log.status != "Success")
& (activity_log.creation > after)
)
.groupby(activity_log.communication_date)
.orderby(activity_log.communication_date, order=frappe.qb.desc)
).run()

timeline_items = dict(data)

Expand Down

0 comments on commit 6d25ba9

Please sign in to comment.