Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Enterprise SMS Report #35437

Merged
merged 11 commits into from
Dec 4, 2024
16 changes: 12 additions & 4 deletions corehq/apps/enterprise/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ def __init__(self, account, couch_user, start_date=None, end_date=None, num_days
def total_for_domain(self, domain_obj):
query = SMS.objects.filter(
domain=domain_obj.name,
processed=True,
jingcheng16 marked this conversation as resolved.
Show resolved Hide resolved
direction=OUTGOING,
error=False,
date__gte=self.datespan.startdate,
date__lt=self.datespan.enddate_adjusted
)
Expand All @@ -436,11 +438,17 @@ def headers(self):
return headers

def rows_for_domain(self, domain_obj):
results = SMS.objects.filter(domain=domain_obj.name) \
.values('direction', 'error').annotate(direction_count=Count('pk'))
results = SMS.objects.filter(
domain=domain_obj.name,
processed=True,
date__gte=self.datespan.startdate,
date__lt=self.datespan.enddate_adjusted
).values('direction', 'error').annotate(direction_count=Count('pk'))

num_sent = sum([result['direction_count'] for result in results if result['direction'] == OUTGOING])
num_received = sum([result['direction_count'] for result in results if result['direction'] == INCOMING])
num_sent = sum([result['direction_count'] for result in results
if result['direction'] == OUTGOING and not result['error']])
num_received = sum([result['direction_count'] for result in results
if result['direction'] == INCOMING and not result['error']])
num_errors = sum([result['direction_count'] for result in results if result['error']])

return [(domain_obj.name, num_sent, num_received, num_errors), ]
Loading