Wire order records to bills, fix user balance

This commit is contained in:
fnux 2020-03-02 10:46:04 +01:00
commit 9e9018060e
3 changed files with 46 additions and 21 deletions

View file

@ -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):