Skip to content

Commit

Permalink
refactor: Outbound Delay report
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Oct 5, 2024
1 parent 3b2097b commit 56bbfd4
Showing 1 changed file with 25 additions and 41 deletions.
66 changes: 25 additions & 41 deletions mail/mail/report/outbound_delay/outbound_delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Tuple
from frappe.query_builder import Order, Criterion
from mail.utils.cache import get_user_owned_domains
from frappe.query_builder.functions import Date, IfNull
from frappe.query_builder.functions import Sum, Date, IfNull
from mail.utils.user import has_role, is_system_manager, get_user_mailboxes


Expand Down Expand Up @@ -36,19 +36,21 @@ def get_data(filters=None) -> list:
OM.message_size,
OM.via_api,
OM.is_newsletter,
OM.submitted_after,
OM.transfer_completed_after.as_("transferred_after"),
MR.action_after,
OM.submitted_after.as_("submission_delay"),
Sum(OM.transfer_started_after, OM.transfer_completed_after).as_("transfer_delay"),
OM.action_after.as_("action_delay"),
Sum(
OM.submitted_after,
OM.transfer_started_after,
OM.transfer_completed_after,
OM.action_after,
).as_("total_delay"),
OM.agent,
OM.domain_name,
OM.ip_address,
OM.sender,
MR.email.as_("recipient"),
OM.message_id,
OM.created_at,
OM.submitted_at,
OM.transfer_completed_at.as_("transferred_at"),
MR.action_at,
)
.where((OM.docstatus == 1) & (IfNull(MR.status, "") != ""))
.orderby(OM.creation, OM.created_at, order=Order.desc)
Expand Down Expand Up @@ -111,7 +113,7 @@ def get_summary(data: list) -> list[dict]:
status_count[status] += 1

total_message_size += row["message_size"]
total_transfer_delay += row["transferred_after"]
total_transfer_delay += row["transfer_delay"]

return [
{
Expand Down Expand Up @@ -193,22 +195,28 @@ def get_columns() -> list:
"width": 100,
},
{
"label": _("Created After"),
"fieldname": "submitted_after",
"label": _("Submission Delay"),
"fieldname": "submission_delay",
"fieldtype": "Int",
"width": 120,
},
{
"label": _("Transferred After"),
"fieldname": "transferred_after",
"label": _("Transfer Delay"),
"fieldname": "transfer_delay",
"fieldtype": "Int",
"width": 140,
"width": 120,
},
{
"label": _("Action Delay"),
"fieldname": "action_delay",
"fieldtype": "Int",
"width": 120,
},
{
"label": _("Action After"),
"fieldname": "action_after",
"label": _("Total Delay"),
"fieldname": "total_delay",
"fieldtype": "Int",
"width": 110,
"width": 120,
},
{
"label": _("Agent"),
Expand Down Expand Up @@ -249,28 +257,4 @@ def get_columns() -> list:
"fieldtype": "Data",
"width": 200,
},
{
"label": _("Created At"),
"fieldname": "created_at",
"fieldtype": "Datetime",
"width": 180,
},
{
"label": _("Submitted At"),
"fieldname": "submitted_at",
"fieldtype": "Datetime",
"width": 180,
},
{
"label": _("Transferred At"),
"fieldname": "transferred_at",
"fieldtype": "Datetime",
"width": 180,
},
{
"label": _("Action At"),
"fieldname": "action_at",
"fieldtype": "Datetime",
"width": 180,
},
]

0 comments on commit 56bbfd4

Please sign in to comment.