mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-14 08:21:49 +02:00
Compare commits
6 commits
beb1d66793
...
f6762f2d8f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f6762f2d8f | ||
![]() |
61ea1f54d2 | ||
![]() |
299c384908 | ||
![]() |
4e9ff9b1ac | ||
![]() |
2aa410c68f | ||
![]() |
f62ca85ace |
3 changed files with 47 additions and 28 deletions
|
@ -113,42 +113,57 @@ class Project(db.Model):
|
|||
|
||||
@property
|
||||
def full_balance(self):
|
||||
"""Returns a triple of dicts:
|
||||
"""Returns a tuple of dicts:
|
||||
|
||||
- dict mapping each member to its balance
|
||||
- dict mapping each member to its overall balance
|
||||
|
||||
- dict mapping each member to how much he/she should pay others
|
||||
(i.e. how much he/she benefited from bills)
|
||||
- dict mapping each member to its expenses (i.e. how much he/she
|
||||
benefited from all bills, whoever actually paid)
|
||||
|
||||
- dict mapping each member to how much he/she should be paid by
|
||||
others (i.e. how much he/she has paid for bills)
|
||||
- dict mapping each member to how much he/she has paid for bills
|
||||
|
||||
- dict mapping each member to how much he/she has transferred
|
||||
money to other members
|
||||
|
||||
- dict mapping each member to how much he/she has received money
|
||||
from other members
|
||||
|
||||
balance, spent, paid, transferred, received
|
||||
|
||||
balance spent paid
|
||||
"""
|
||||
balances, should_pay, should_receive = (defaultdict(int) for time in (1, 2, 3))
|
||||
balances, spent, paid, transferred, received = (
|
||||
defaultdict(float) for _ in range(5)
|
||||
)
|
||||
for bill in self.get_bills_unordered().all():
|
||||
total_weight = sum(ower.weight for ower in bill.owers)
|
||||
|
||||
if bill.bill_type == BillType.EXPENSE:
|
||||
should_receive[bill.payer.id] += bill.converted_amount
|
||||
paid[bill.payer.id] += bill.converted_amount
|
||||
for ower in bill.owers:
|
||||
should_pay[ower.id] += (
|
||||
spent[ower.id] += ower.weight * bill.converted_amount / total_weight
|
||||
|
||||
if bill.bill_type == BillType.REIMBURSEMENT:
|
||||
transferred[bill.payer.id] += bill.converted_amount
|
||||
for ower in bill.owers:
|
||||
received[ower.id] += (
|
||||
ower.weight * bill.converted_amount / total_weight
|
||||
)
|
||||
|
||||
if bill.bill_type == BillType.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]
|
||||
balance = (
|
||||
paid[person.id]
|
||||
- spent[person.id]
|
||||
+ transferred[person.id]
|
||||
- received[person.id]
|
||||
)
|
||||
balances[person.id] = balance
|
||||
|
||||
return (
|
||||
balances,
|
||||
should_pay,
|
||||
should_receive,
|
||||
spent,
|
||||
paid,
|
||||
transferred,
|
||||
received,
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -157,17 +172,19 @@ class Project(db.Model):
|
|||
|
||||
@property
|
||||
def members_stats(self):
|
||||
"""Compute what each participant has paid
|
||||
"""Compute what each participant has spent, paid, transferred and received
|
||||
|
||||
:return: one stat dict per participant
|
||||
:rtype list:
|
||||
"""
|
||||
balance, spent, paid = self.full_balance
|
||||
balance, spent, paid, transferred, received = self.full_balance
|
||||
return [
|
||||
{
|
||||
"member": member,
|
||||
"spent": -1.0 * spent[member.id],
|
||||
"paid": paid[member.id],
|
||||
"spent": spent[member.id],
|
||||
"transferred": transferred[member.id],
|
||||
"received": -1.0 * received[member.id],
|
||||
"balance": balance[member.id],
|
||||
}
|
||||
for member in self.active_members
|
||||
|
|
|
@ -10,20 +10,22 @@
|
|||
{% block content %}
|
||||
<div class="d-flex flex-column">
|
||||
<table id="bill_table" class="split_bills table table-striped ml-md-n3">
|
||||
<thead><tr><th class="d-md-none">{{ _("Who?") }}</th><th>{{ _("Paid") }}</th><th>{{ _("Spent") }}</th></tr></thead>
|
||||
<thead><tr><th class="d-md-none">{{ _("Who?") }}</th><th>{{ _("Paid") }}</th><th>{{ _("Expenses") }}</th><th>{{ _("Transferred") }}</th><th>{{ _("Received") }}</th></tr></thead>
|
||||
<tbody>
|
||||
{% for stat in members_stats|sort(attribute='member.name') %}
|
||||
<tr>
|
||||
<td class="d-md-none">{{ stat.member.name }}</td>
|
||||
<td>{{ stat.paid|currency }}</td>
|
||||
<td>{{ stat.spent|currency }}</td>
|
||||
<td>{{ stat.transferred|currency }}</td>
|
||||
<td>{{ stat.received|currency }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>{{ _("Expenses by Month") }}</h2>
|
||||
<h2>{{ _("Expenses by month") }}</h2>
|
||||
<table id="monthly_stats" class="table table-striped">
|
||||
<thead><tr><th>{{ _("Period") }}</th><th>{{ _("Spent") }}</th></tr></thead>
|
||||
<thead><tr><th>{{ _("Period") }}</th><th>{{ _("Expenses") }}</th></tr></thead>
|
||||
<tbody>
|
||||
{% for month in months %}
|
||||
<tr>
|
||||
|
|
|
@ -27,7 +27,7 @@ classifiers = [
|
|||
|
||||
dependencies = [
|
||||
"blinker>=1.4,<2",
|
||||
"cachetools>=4.1,<5",
|
||||
"cachetools>=4.1,<6",
|
||||
"debts>=0.5,<1",
|
||||
"email_validator>=1.0,<3",
|
||||
"Flask>=2,<4",
|
||||
|
@ -43,7 +43,7 @@ dependencies = [
|
|||
"itsdangerous>=2,<3",
|
||||
"Jinja2>=3,<4",
|
||||
"python-dateutil",
|
||||
"qrcode>=7.1,<8",
|
||||
"qrcode>=7.1,<9",
|
||||
"requests>=2.25,<3",
|
||||
"SQLAlchemy>=1.3.0,<1.5",
|
||||
"SQLAlchemy-Continuum>=1.3.12,<2", # New 1.4 changes API, see #728
|
||||
|
@ -53,11 +53,11 @@ dependencies = [
|
|||
[project.optional-dependencies]
|
||||
database = [
|
||||
# Python 3.11 support starts in 2.9.2
|
||||
"psycopg2-binary>=2.9.2,<2.9.9",
|
||||
"psycopg2-binary>=2.9.2,<2.9.11",
|
||||
"PyMySQL>=0.9,<1.2",
|
||||
]
|
||||
dev = [
|
||||
"ruff==0.6.8",
|
||||
"ruff==0.8.4",
|
||||
"flake8==5.0.4",
|
||||
"isort==5.11.5",
|
||||
"vermin==1.6.0",
|
||||
|
|
Loading…
Reference in a new issue