mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-14 16:31:49 +02:00
Compare commits
3 commits
ace80da693
...
beb1d66793
Author | SHA1 | Date | |
---|---|---|---|
![]() |
beb1d66793 | ||
![]() |
7505cbe25a | ||
![]() |
f62ca85ace |
8 changed files with 63 additions and 26 deletions
|
@ -173,6 +173,14 @@ URL you want.
|
||||||
- **Default value:** `""` (empty string)
|
- **Default value:** `""` (empty string)
|
||||||
- **Production value:** The URL of your chosing.
|
- **Production value:** The URL of your chosing.
|
||||||
|
|
||||||
|
## SITE_NAME
|
||||||
|
|
||||||
|
It is possible to change the name of the site to something at your liking.
|
||||||
|
|
||||||
|
- **Default value:** `"I Hate Money"` (empty string)
|
||||||
|
- **Production value:** The name of your choosing
|
||||||
|
|
||||||
|
|
||||||
## Configuring email sending
|
## Configuring email sending
|
||||||
|
|
||||||
By default, Ihatemoney sends emails using a local SMTP server, but it's
|
By default, Ihatemoney sends emails using a local SMTP server, but it's
|
||||||
|
|
|
@ -3,6 +3,7 @@ DEBUG = SQLACHEMY_ECHO = False
|
||||||
SQLALCHEMY_DATABASE_URI = "sqlite:////tmp/ihatemoney.db"
|
SQLALCHEMY_DATABASE_URI = "sqlite:////tmp/ihatemoney.db"
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
SECRET_KEY = "tralala"
|
SECRET_KEY = "tralala"
|
||||||
|
SITE_NAME = "I Hate Money"
|
||||||
MAIL_DEFAULT_SENDER = "Budget manager <admin@example.com>"
|
MAIL_DEFAULT_SENDER = "Budget manager <admin@example.com>"
|
||||||
SHOW_ADMIN_EMAIL = True
|
SHOW_ADMIN_EMAIL = True
|
||||||
ACTIVATE_DEMO_PROJECT = True
|
ACTIVATE_DEMO_PROJECT = True
|
||||||
|
|
|
@ -113,42 +113,57 @@ class Project(db.Model):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_balance(self):
|
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
|
- dict mapping each member to its expenses (i.e. how much he/she
|
||||||
(i.e. how much he/she benefited from bills)
|
benefited from all bills, whoever actually paid)
|
||||||
|
|
||||||
- dict mapping each member to how much he/she should be paid by
|
- dict mapping each member to how much he/she has paid for bills
|
||||||
others (i.e. 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():
|
for bill in self.get_bills_unordered().all():
|
||||||
total_weight = sum(ower.weight for ower in bill.owers)
|
total_weight = sum(ower.weight for ower in bill.owers)
|
||||||
|
|
||||||
if bill.bill_type == BillType.EXPENSE:
|
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:
|
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
|
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:
|
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
|
balances[person.id] = balance
|
||||||
|
|
||||||
return (
|
return (
|
||||||
balances,
|
balances,
|
||||||
should_pay,
|
spent,
|
||||||
should_receive,
|
paid,
|
||||||
|
transferred,
|
||||||
|
received,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -157,17 +172,19 @@ class Project(db.Model):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def members_stats(self):
|
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
|
:return: one stat dict per participant
|
||||||
:rtype list:
|
:rtype list:
|
||||||
"""
|
"""
|
||||||
balance, spent, paid = self.full_balance
|
balance, spent, paid, transferred, received = self.full_balance
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"member": member,
|
"member": member,
|
||||||
|
"spent": -1.0 * spent[member.id],
|
||||||
"paid": paid[member.id],
|
"paid": paid[member.id],
|
||||||
"spent": spent[member.id],
|
"transferred": transferred[member.id],
|
||||||
|
"received": -1.0 * received[member.id],
|
||||||
"balance": balance[member.id],
|
"balance": balance[member.id],
|
||||||
}
|
}
|
||||||
for member in self.active_members
|
for member in self.active_members
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="h-100">
|
<html class="h-100">
|
||||||
<head>
|
<head>
|
||||||
<title>{{ _("Account manager") }}{% block title %}{% endblock %}</title>
|
<title>{{ SITE_NAME }} — {{ _("Account manager") }}{% block title %}{% endblock %}</title>
|
||||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel=stylesheet type=text/css href="{{ url_for("static", filename='css/main.css') }}">
|
<link rel=stylesheet type=text/css href="{{ url_for("static", filename='css/main.css') }}">
|
||||||
|
|
|
@ -10,20 +10,22 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="d-flex flex-column">
|
<div class="d-flex flex-column">
|
||||||
<table id="bill_table" class="split_bills table table-striped ml-md-n3">
|
<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>
|
<tbody>
|
||||||
{% for stat in members_stats|sort(attribute='member.name') %}
|
{% for stat in members_stats|sort(attribute='member.name') %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="d-md-none">{{ stat.member.name }}</td>
|
<td class="d-md-none">{{ stat.member.name }}</td>
|
||||||
<td>{{ stat.paid|currency }}</td>
|
<td>{{ stat.paid|currency }}</td>
|
||||||
<td>{{ stat.spent|currency }}</td>
|
<td>{{ stat.spent|currency }}</td>
|
||||||
|
<td>{{ stat.transferred|currency }}</td>
|
||||||
|
<td>{{ stat.received|currency }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<h2>{{ _("Expenses by Month") }}</h2>
|
<h2>{{ _("Expenses by month") }}</h2>
|
||||||
<table id="monthly_stats" class="table table-striped">
|
<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>
|
<tbody>
|
||||||
{% for month in months %}
|
{% for month in months %}
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -238,7 +238,10 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
url, data={"password": "pass", "password_confirmation": "pass"}
|
url, data={"password": "pass", "password_confirmation": "pass"}
|
||||||
)
|
)
|
||||||
resp = self.login("raclette", password="pass")
|
resp = self.login("raclette", password="pass")
|
||||||
assert "<title>Account manager - raclette</title>" in resp.data.decode("utf-8")
|
assert (
|
||||||
|
"<title>I Hate Money — Account manager - raclette</title>"
|
||||||
|
in resp.data.decode("utf-8")
|
||||||
|
)
|
||||||
# Test empty and null tokens
|
# Test empty and null tokens
|
||||||
resp = self.client.get("/reset-password")
|
resp = self.client.get("/reset-password")
|
||||||
assert "No token provided" in resp.data.decode("utf-8")
|
assert "No token provided" in resp.data.decode("utf-8")
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///budget.db'
|
SQLALCHEMY_DATABASE_URI = 'sqlite:///budget.db'
|
||||||
SQLACHEMY_ECHO = DEBUG
|
SQLACHEMY_ECHO = DEBUG
|
||||||
|
SITE_NAME = "I Hate Money"
|
||||||
|
|
||||||
SECRET_KEY = "supersecret"
|
SECRET_KEY = "supersecret"
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,11 @@ def set_show_admin_dashboard_link(endpoint, values):
|
||||||
g.logout_form = LogoutForm()
|
g.logout_form = LogoutForm()
|
||||||
|
|
||||||
|
|
||||||
|
@main.context_processor
|
||||||
|
def add_template_variables():
|
||||||
|
return {"SITE_NAME": current_app.config.get("SITE_NAME")}
|
||||||
|
|
||||||
|
|
||||||
@main.url_value_preprocessor
|
@main.url_value_preprocessor
|
||||||
def pull_project(endpoint, values):
|
def pull_project(endpoint, values):
|
||||||
"""When a request contains a project_id value, transform it directly
|
"""When a request contains a project_id value, transform it directly
|
||||||
|
|
Loading…
Reference in a new issue