Skip to content

Commit

Permalink
Adding in some files
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Aug 5, 2013
1 parent 645a2f7 commit b5fac9a
Show file tree
Hide file tree
Showing 4 changed files with 951 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.py[cod]
*__py

# C extensions
*.so
Expand Down
101 changes: 101 additions & 0 deletions djstripe/managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""
Beging porting from django-stripe-payments
"""
from __future__ import unicode_literals
import decimal

from django.db import models


class CustomerManager(models.Manager):

def started_during(self, year, month):
return self.exclude(
current_subscription__status="trialing"
).filter(
current_subscription__start__year=year,
current_subscription__start__month=month
)

def active(self):
return self.filter(
current_subscription__status="active"
)

def canceled(self):
return self.filter(
current_subscription__status="canceled"
)

def canceled_during(self, year, month):
return self.canceled().filter(
current_subscription__canceled_at__year=year,
current_subscription__canceled_at__month=month,
)

def started_plan_summary_for(self, year, month):
return self.started_during(year, month).values(
"current_subscription__plan"
).order_by().annotate(
count=models.Count("current_subscription__plan")
)

def active_plan_summary(self):
return self.active().values(
"current_subscription__plan"
).order_by().annotate(
count=models.Count("current_subscription__plan")
)

def canceled_plan_summary_for(self, year, month):
return self.canceled_during(year, month).values(
"current_subscription__plan"
).order_by().annotate(
count=models.Count("current_subscription__plan")
)

def churn(self):
canceled = self.canceled().count()
active = self.active().count()
return decimal.Decimal(str(canceled)) / decimal.Decimal(str(active))


class TransferManager(models.Manager):

def during(self, year, month):
return self.filter(
date__year=year,
date__month=month
)

def paid_totals_for(self, year, month):
return self.during(year, month).filter(
status="paid"
).aggregate(
total_gross=models.Sum("charge_gross"),
total_net=models.Sum("net"),
total_charge_fees=models.Sum("charge_fees"),
total_adjustment_fees=models.Sum("adjustment_fees"),
total_refund_gross=models.Sum("refund_gross"),
total_refund_fees=models.Sum("refund_fees"),
total_validation_fees=models.Sum("validation_fees"),
total_amount=models.Sum("amount")
)


class ChargeManager(models.Manager):

def during(self, year, month):
return self.filter(
charge_created__year=year,
charge_created__month=month
)

def paid_totals_for(self, year, month):
return self.during(year, month).filter(
paid=True
).aggregate(
total_amount=models.Sum("amount"),
total_fee=models.Sum("fee"),
total_refunded=models.Sum("amount_refunded")
)
Loading

0 comments on commit b5fac9a

Please sign in to comment.