fix: accommodate for changed orderby statement (cherry picked from commit 87df7ff71772474bb858dac6ce9132280ce2ab82) Co-authored-by: Gursheen Anand <gursheen@frappe.io>
This commit is contained in:
parent
afc87a4486
commit
6662c321a5
@ -9,7 +9,7 @@ from frappe import _, msgprint, qb, scrub
|
|||||||
from frappe.contacts.doctype.address.address import get_company_address, get_default_address
|
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.core.doctype.user_permission.user_permission import get_permitted_documents
|
||||||
from frappe.model.utils import get_fetch_values
|
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 (
|
from frappe.utils import (
|
||||||
add_days,
|
add_days,
|
||||||
add_months,
|
add_months,
|
||||||
@ -784,34 +784,37 @@ def get_timeline_data(doctype, name):
|
|||||||
from frappe.desk.form.load import get_communication_data
|
from frappe.desk.form.load import get_communication_data
|
||||||
|
|
||||||
out = {}
|
out = {}
|
||||||
fields = "creation, count(*)"
|
|
||||||
after = add_years(None, -1).strftime("%Y-%m-%d")
|
after = add_years(None, -1).strftime("%Y-%m-%d")
|
||||||
group_by = "group by Date(creation)"
|
|
||||||
|
|
||||||
data = get_communication_data(
|
data = get_communication_data(
|
||||||
doctype,
|
doctype,
|
||||||
name,
|
name,
|
||||||
after=after,
|
after=after,
|
||||||
group_by="group by creation",
|
group_by="group by communication_date",
|
||||||
fields="C.creation as creation, count(C.name)",
|
fields="C.communication_date as communication_date, count(C.name)",
|
||||||
as_dict=False,
|
as_dict=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# fetch and append data from Activity Log
|
# fetch and append data from Activity Log
|
||||||
data += frappe.db.sql(
|
activity_log = frappe.qb.DocType("Activity Log")
|
||||||
"""select {fields}
|
data += (
|
||||||
from `tabActivity Log`
|
frappe.qb.from_(activity_log)
|
||||||
where (reference_doctype=%(doctype)s and reference_name=%(name)s)
|
.select(activity_log.communication_date, Count(activity_log.name))
|
||||||
or (timeline_doctype in (%(doctype)s) and timeline_name=%(name)s)
|
.where(
|
||||||
or (reference_doctype in ("Quotation", "Opportunity") and timeline_name=%(name)s)
|
(
|
||||||
and status!='Success' and creation > {after}
|
((activity_log.reference_doctype == doctype) & (activity_log.reference_name == name))
|
||||||
{group_by} order by creation desc
|
| ((activity_log.timeline_doctype == doctype) & (activity_log.timeline_name == name))
|
||||||
""".format(
|
| (
|
||||||
fields=fields, group_by=group_by, after=after
|
(activity_log.reference_doctype.isin(["Quotation", "Opportunity"]))
|
||||||
),
|
& (activity_log.timeline_name == name)
|
||||||
{"doctype": doctype, "name": name},
|
)
|
||||||
as_dict=False,
|
)
|
||||||
)
|
& (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)
|
timeline_items = dict(data)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user