forked from uncloud/uncloud
Add initial generate-bills and charge-negative-balance uncloud-pay
commands
This commit is contained in:
parent
ef5e7e8035
commit
059791e2f2
10 changed files with 275 additions and 12 deletions
12
uncloud/uncloud_pay/helpers.py
Normal file
12
uncloud/uncloud_pay/helpers.py
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue