Add initial generate-bills and charge-negative-balance uncloud-pay

commands
This commit is contained in:
fnux 2020-02-28 08:59:32 +01:00
commit 059791e2f2
10 changed files with 275 additions and 12 deletions

View file

@ -0,0 +1,12 @@
from functools import reduce
from .models import Bill, Payment
def sum_amounts(entries):
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