Exemplo n.º 1
0
    def get(self, request, table_key, *args, **kwargs):
        ends_at = request.GET.get('ends_at', None)
        if ends_at:
            ends_at = parse_datetime(ends_at)
        ends_at = datetime_or_now(ends_at)

        reverse = True
        account_title = 'Payments'
        account = Transaction.FUNDS

        # TODO: refactor to only build the table (customer or amount)
        # relevant to the request

        account_table, customer_table, customer_extra = \
            aggregate_monthly_transactions(self.get_organization(), account,
                account_title=account_title,
                from_date=ends_at,
                reverse=reverse)
        data = SortedDict()
        # By convention, if we have a ``unit``, the table contains
        # amounts in cents. We thus scale by 0.01 to get a human
        # readable 'whole dollar' amounts.
        data['amount'] = {
            "title": "Amount",
            "unit": "$",
            "scale": 0.01,
            "table": account_table
        }
        data['customers'] = {
            "title": "Customers",
            "table": customer_table,
            "extra": customer_extra
        }
        return Response({"title": "Revenue Metrics", "data": data[table_key]})
Exemplo n.º 2
0
    def get(self, request, *args, **kwargs):
        ends_at = request.GET.get('ends_at', None)
        if ends_at:
            ends_at = parse_datetime(ends_at)
        ends_at = datetime_or_now(ends_at)

        # XXX to fix: returns payments in customer currency
        account_table, _, _ = \
            aggregate_monthly_transactions(self.get_organization(),
                Transaction.FUNDS, account_title='Payments',
                from_date=ends_at, orig='dest', dest='orig')

        _, refund_amount = aggregate_monthly(self.get_organization(),
                                             Transaction.REFUND,
                                             from_date=ends_at,
                                             orig='dest',
                                             dest='dest')

        account_table += [{"key": "Refunds", "values": refund_amount}]

        return Response({
            "title": "Amount",
            "unit": "$",
            "scale": 0.01,
            "table": account_table
        })
Exemplo n.º 3
0
    def get(self, request, table_key, *args, **kwargs):
        ends_at = request.GET.get('ends_at', None)
        if ends_at:
            ends_at = parse_datetime(ends_at)
        ends_at = datetime_or_now(ends_at)

        reverse = True
        account_title = 'Payments'
        account = Transaction.FUNDS

        # TODO: refactor to only build the table (customer or amount)
        # relevant to the request

        account_table, customer_table, customer_extra = \
            aggregate_monthly_transactions(self.get_organization(), account,
                account_title=account_title,
                from_date=ends_at,
                reverse=reverse)
        data = SortedDict()
        # By convention, if we have a ``unit``, the table contains
        # amounts in cents. We thus scale by 0.01 to get a human
        # readable 'whole dollar' amounts.
        data['amount'] = {"title": "Amount",
                          "unit": "$", "scale": 0.01, "table": account_table}
        data['customers'] = {"title": "Customers",
                             "table": customer_table, "extra": customer_extra}
        return Response(
            {"title": "Revenue Metrics",
            "data": data[table_key]})
Exemplo n.º 4
0
 def test_monthly_income(self):
     """Jan 2012: ABC has 2 customers,
     Feb 2012: ABC lost 1 customer,
     Mar 2012: ABC gains 1 customer,
     Apr 2012: ABC lost 1 customer and gains 1 customer,
     May 2012: No change."""
     table, _, _ = aggregate_monthly_transactions(
         Organization.objects.get(pk=2),
         from_date=date(year=2014, month=1, day=1))
     for entry in table:
         values = entry["values"]
         if entry["key"] == "Total # of Customers":
             self.assertTrue(values[0][1] == 2)
             self.assertTrue(values[1][1] == 1)
             self.assertTrue(values[2][1] == 2)
             self.assertTrue(values[3][1] == 2)
             self.assertTrue(values[4][1] == 2)
             self.assertTrue(values[4][1] == 2)
         elif entry["key"] == "# of new Customers":
             self.assertTrue(values[0][1] == 2)  # We have no records before
             self.assertTrue(values[1][1] == 0)
             self.assertTrue(values[2][1] == 1)
             self.assertTrue(values[3][1] == 1)
             self.assertTrue(values[4][1] == 0)
             self.assertTrue(values[4][1] == 0)
         elif entry["key"] == "# of churned Customers":
             self.assertTrue(values[0][1] == 0)
             self.assertTrue(values[1][1] == 1)
             self.assertTrue(values[2][1] == 0)
             self.assertTrue(values[3][1] == 1)
             self.assertTrue(values[4][1] == 0)
             self.assertTrue(values[4][1] == 0)
Exemplo n.º 5
0
 def get_context_data(self, **kwargs):
     context = super(RevenueMetricsView, self).get_context_data(**kwargs)
     organization = self.get_organization()
     from_date = kwargs.get('from_date', None)
     income_table, customer_table, customer_extra = \
         aggregate_monthly_transactions(organization, from_date)
     data = SortedDict()
     data['amount'] = {"title": "Amount",
                       "unit": "$", "table": income_table}
     data['customers'] = {"title": "Customers",
                          "table": customer_table, "extra": customer_extra}
     context.update({"title": "Revenue Metrics",
         "data": data,
         "data_json": json.dumps(data, cls=DjangoJSONEncoder)})
     return context
Exemplo n.º 6
0
    def get(self, request, *args, **kwargs):
        ends_at = request.GET.get('ends_at', None)
        if ends_at:
            ends_at = parse_datetime(ends_at)
        ends_at = datetime_or_now(ends_at)

        account_title = 'Payments'
        account = Transaction.RECEIVABLE
        # We use ``Transaction.RECEIVABLE`` which technically counts the number
        # or orders, not the number of payments.

        _, customer_table, customer_extra = \
            aggregate_monthly_transactions(self.get_organization(), account,
                account_title=account_title,
                from_date=ends_at)

        return Response(
            {"title": "Customers",
                "table": customer_table, "extra": customer_extra})
Exemplo n.º 7
0
    def get(self, request, *args, **kwargs):
        ends_at = request.GET.get('ends_at', None)
        if ends_at:
            ends_at = parse_datetime(ends_at)
        ends_at = datetime_or_now(ends_at)

        account_title = 'Payments'
        account = Transaction.RECEIVABLE
        # We use ``Transaction.RECEIVABLE`` which technically counts the number
        # or orders, not the number of payments.

        _, customer_table, customer_extra = \
            aggregate_monthly_transactions(self.get_organization(), account,
                account_title=account_title,
                from_date=ends_at)

        return Response({
            "title": "Customers",
            "table": customer_table,
            "extra": customer_extra
        })
Exemplo n.º 8
0
    def get(self, request, *args, **kwargs):
        ends_at = request.GET.get('ends_at', None)
        if ends_at:
            ends_at = parse_datetime(ends_at)
        ends_at = datetime_or_now(ends_at)

        # XXX to fix: returns payments in customer currency
        account_table, _, _ = \
            aggregate_monthly_transactions(self.get_organization(),
                Transaction.FUNDS, account_title='Payments',
                from_date=ends_at, orig='dest', dest='orig')

        _, refund_amount = aggregate_monthly(
            self.get_organization(), Transaction.REFUND,
            from_date=ends_at, orig='dest', dest='dest')

        account_table += [{"key": "Refunds",
                           "values": refund_amount}]

        return Response(
            {"title": "Amount",
            "unit": "$", "scale": 0.01, "table": account_table})