forked from uncloud/uncloud
Wire order records to bills, fix user balance
This commit is contained in:
parent
9e253d497b
commit
9e9018060e
3 changed files with 46 additions and 21 deletions
|
|
@ -8,12 +8,15 @@ from django.utils import timezone
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from calendar import monthrange
|
||||
|
||||
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))
|
||||
bills = reduce(
|
||||
lambda acc, entry: acc + entry.total,
|
||||
Bill.objects.filter(owner=user),
|
||||
0)
|
||||
payments = reduce(
|
||||
lambda acc, entry: acc + entry.amount,
|
||||
Payment.objects.filter(owner=user),
|
||||
0)
|
||||
return payments - bills
|
||||
|
||||
def get_payment_method_for(user):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue