diff --git a/cloud/endagaweb/models.py b/cloud/endagaweb/models.py index 65b0780f..2cc602a1 100644 --- a/cloud/endagaweb/models.py +++ b/cloud/endagaweb/models.py @@ -525,6 +525,7 @@ class Subscriber(models.Model): # When toggled, this will protect a subsriber from getting "vacuumed." You # can still delete subs with the usual "deactivate" button. prevent_automatic_deactivation = models.BooleanField(default=False) + role = models.TextField(default='retailer') @classmethod def update_balance(cls, imsi, other_bal): diff --git a/cloud/endagaweb/stats_app/stats_client.py b/cloud/endagaweb/stats_app/stats_client.py index 5ebe043f..791d0260 100644 --- a/cloud/endagaweb/stats_app/stats_client.py +++ b/cloud/endagaweb/stats_app/stats_client.py @@ -369,3 +369,32 @@ def timeseries(self, key=None, **kwargs): if 'aggregation' not in kwargs: kwargs['aggregation'] = 'average_value' return self.aggregate_timeseries(key, **kwargs) + + +class TransferStatsClient(StatsClientBase): + """ Gather retailer transfer and recharge report """ + + def __init__(self, *args, **kwargs): + super(TransferStatsClient, self).__init__(*args, **kwargs) + + def timeseries(self, kind=None, **kwargs): + # Set queryset from subscriber role as retailer + kwargs['query'] = Q(subscriber__role='retailer') + return self.aggregate_timeseries(kind, **kwargs) + + +class TopUpStatsClient(StatsClientBase): + def __init__(self, *args, **kwargs): + super(TopUpStatsClient, self).__init__(*args, **kwargs) + + def timeseries(self, kind=None, **kwargs): + # Change is negative convert to compare + try: + raw_amount = [(float(denom) * -1 / 100000) for denom in + kwargs['extras'].split('-')] + kwargs['query'] = Q(change__gte=raw_amount[1]) & Q( + change__lte=raw_amount[0]) & Q(subscriber__role='retailer') + return self.aggregate_timeseries(kind, **kwargs) + except ValueError: + # If no denominations available in this network + raise ValueError('no denominations available in current network') diff --git a/cloud/endagaweb/templates/dashboard/report/billing.html b/cloud/endagaweb/templates/dashboard/report/billing.html new file mode 100644 index 00000000..56024ac8 --- /dev/null +++ b/cloud/endagaweb/templates/dashboard/report/billing.html @@ -0,0 +1,368 @@ +{% extends "dashboard/layout.html" %} +{% comment %} +Copyright (c) 2016-present, Facebook, Inc. +All rights reserved. + +This source code is licensed under the BSD-style license found in the +LICENSE file in the root directory of this source tree. An additional grant +of patent rights can be found in the PATENTS file in the same directory. +{% endcomment %} +{% load apptags %} +{% load humanize %} +{% load crispy_forms_tags %} + + +{% block title %} + {% tmpl_const "SITENAME" %} | Report + {% if report_summary %} + | "{{ report_summary }}" + {% endif %} +{% endblock %} + +{% block pagestyle %} + + + + +{% endblock %} + +{% block content %} + {% include "dashboard/report/header.html" with header='Billing' %} + +
There is no network activity to display.
+ {% endif %} +