forked from uncloud/uncloud
Wire charge-negative-balance to payment methods
This commit is contained in:
parent
059791e2f2
commit
4bed53c8a8
3 changed files with 25 additions and 7 deletions
|
|
@ -1,12 +1,20 @@
|
|||
from functools import reduce
|
||||
from .models import Bill, Payment
|
||||
from .models import Bill, Payment, PaymentMethod
|
||||
|
||||
def sum_amounts(entries):
|
||||
return reduce(lambda acc, entry: acc + entry.amount, entries, 0)
|
||||
return reduce(lambda acc, entry: acc + entry.amount, entries, 0)
|
||||
|
||||
|
||||
def get_balance_for(user):
|
||||
bills = sum_amounts(Bill.objects.filter(owner=user))
|
||||
payments = sum_amounts(Payment.objects.filter(owner=user))
|
||||
return payments - bills
|
||||
bills = sum_amounts(Bill.objects.filter(owner=user))
|
||||
payments = sum_amounts(Payment.objects.filter(owner=user))
|
||||
return payments - bills
|
||||
|
||||
def get_payment_method_for(user):
|
||||
methods = PaymentMethod.objects.filter(owner=user)
|
||||
for method in methods:
|
||||
# Do we want to do something with non-primary method?
|
||||
if method.primary:
|
||||
return method
|
||||
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue