mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-30 18:22:38 +02:00
bchen-reimbursement
This commit is contained in:
parent
5fc8b822a1
commit
40fc02bb6b
1 changed files with 26 additions and 9 deletions
|
@ -109,28 +109,44 @@ class Project(db.Model):
|
|||
|
||||
- dict mapping each member to its balance
|
||||
|
||||
- dict mapping each member to how much he/she should pay others
|
||||
- dict mapping each member to how much he/she she should pay others
|
||||
(i.e. how much he/she benefited from bills)
|
||||
|
||||
- dict mapping each member to how much he/she should be paid by
|
||||
others (i.e. how much he/she has paid for bills)
|
||||
|
||||
balance spent paid
|
||||
"""
|
||||
balances, should_pay, should_receive = (defaultdict(int) for time in (1, 2, 3))
|
||||
|
||||
# for bill in self.get_bills_unordered().all():
|
||||
# should_receive[bill.payer.id] += bill.converted_amount
|
||||
# total_weight = sum(ower.weight for ower in bill.owers)
|
||||
# for ower in bill.owers:
|
||||
# should_pay[ower.id] += (
|
||||
# ower.weight * bill.converted_amount / total_weight
|
||||
# )
|
||||
for bill in self.get_bills_unordered().all():
|
||||
should_receive[bill.payer.id] += bill.converted_amount
|
||||
total_weight = sum(ower.weight for ower in bill.owers)
|
||||
|
||||
if bill.bill_type == "Expense":
|
||||
should_receive[bill.payer.id] += bill.converted_amount
|
||||
for ower in bill.owers:
|
||||
should_pay[ower.id] += (
|
||||
ower.weight * bill.converted_amount / total_weight
|
||||
)
|
||||
should_pay[ower.id] += (ower.weight * bill.converted_amount / total_weight)
|
||||
|
||||
if bill.bill_type == "Reimbursement":
|
||||
should_receive[bill.payer.id] += bill.converted_amount
|
||||
for ower in bill.owers:
|
||||
should_receive[ower.id] -= bill.converted_amount
|
||||
|
||||
for person in self.members:
|
||||
balance = should_receive[person.id] - should_pay[person.id]
|
||||
balances[person.id] = balance
|
||||
|
||||
return balances, should_pay, should_receive
|
||||
return (
|
||||
balances,
|
||||
should_pay,
|
||||
should_receive,
|
||||
)
|
||||
|
||||
@property
|
||||
def balance(self):
|
||||
|
@ -163,6 +179,7 @@ class Project(db.Model):
|
|||
"""
|
||||
monthly = defaultdict(lambda: defaultdict(float))
|
||||
for bill in self.get_bills_unordered().all():
|
||||
if bill.bill_type == "Expense":
|
||||
monthly[bill.date.year][bill.date.month] += bill.converted_amount
|
||||
return monthly
|
||||
|
||||
|
|
Loading…
Reference in a new issue