mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Start working on archive management
This commit is contained in:
parent
295beeade4
commit
801802836a
7 changed files with 55 additions and 17 deletions
|
@ -100,3 +100,8 @@ class InviteForm(Form):
|
|||
if not validator.regex.match(email):
|
||||
raise ValidationError("The email %s is not valid" % email)
|
||||
|
||||
|
||||
class CreateArchiveForm(Form):
|
||||
start_date = DateField("Start date", validators=[Required(),])
|
||||
end_date = DateField("End date", validators=[Required(),])
|
||||
name = TextField("Name for this archive (optional)")
|
||||
|
|
|
@ -78,6 +78,8 @@ class Bill(db.Model):
|
|||
date = db.Column(db.Date, default=datetime.now)
|
||||
what = db.Column(db.UnicodeText)
|
||||
|
||||
archive = db.Column(db.Integer, db.ForeignKey("archive.id"))
|
||||
|
||||
def pay_each(self):
|
||||
"""Compute what each person has to pay"""
|
||||
return round(self.amount / len(self.owers), 2)
|
||||
|
@ -87,3 +89,18 @@ class Bill(db.Model):
|
|||
self.payer, ", ".join([o.name for o in self.owers]))
|
||||
|
||||
|
||||
class Archive(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
project_id = db.Column(db.Integer, db.ForeignKey("project.id"))
|
||||
name = db.Column(db.UnicodeText)
|
||||
|
||||
@property
|
||||
def start_date(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def end_date(self):
|
||||
pass
|
||||
|
||||
def __repr__(self):
|
||||
return "<Archive>"
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% if edit %}Edit a{% else %}Add a new{% endif %} bill</h2>
|
||||
|
||||
<form method="post">
|
||||
{{ forms.add_bill(form) }}
|
||||
{{ forms.add_bill(form, edit) }}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
7
budget/templates/create_archive.html
Normal file
7
budget/templates/create_archive.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post" accept-charset="utf-8">
|
||||
{{ forms.create_archive(form) }}
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -52,10 +52,10 @@
|
|||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro add_bill(form) %}
|
||||
{% macro add_bill(form, edit=False) %}
|
||||
|
||||
<fieldset>
|
||||
<legend>Add a bill</legend>
|
||||
<legend>{% if edit %}Edit this {% else %}Add a {% endif %}bill</legend>
|
||||
{% include "display_errors.html" %}
|
||||
{{ form.hidden_tag() }}
|
||||
{{ input(form.date) }}
|
||||
|
@ -83,3 +83,15 @@
|
|||
<a href="{{ url_for("list_bills") }}">No, thanks</a>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro create_archive(form) %}
|
||||
<fieldset>
|
||||
<legend>Create an archive</legend>
|
||||
{{ form.hidden_tag() }}
|
||||
{{ input(form.start_date) }}
|
||||
{{ input(form.end_date) }}
|
||||
</fieldset>
|
||||
<div class="actions">
|
||||
<button class="btn">Create the archive</button>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<td>{% for ower in bill.owers %}{{ ower.name }} {% endfor %}</td>
|
||||
<td>{{ bill.amount }} ({{ bill.pay_each() }} each)</td>
|
||||
<td><a href="{{ url_for("edit_bill", bill_id=bill.id) }}">edit</a>
|
||||
<a href="{{ url_for("delete_bill", bill_id=bill.id) }}">delete</a></td>
|
||||
<a class="delete" href="{{ url_for("delete_bill", bill_id=bill.id) }}">delete</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -5,7 +5,8 @@ from flaskext.mail import Mail, Message
|
|||
|
||||
# local modules
|
||||
from models import db, Project, Person, Bill
|
||||
from forms import ProjectForm, AuthenticationForm, BillForm, MemberForm, InviteForm
|
||||
from forms import (ProjectForm, AuthenticationForm, BillForm, MemberForm,
|
||||
InviteForm, CreateArchiveForm)
|
||||
from utils import get_billform_for, Redirect303
|
||||
|
||||
# create the application, initialize stuff
|
||||
|
@ -256,18 +257,15 @@ def compute_bills():
|
|||
"""Compute the sum each one have to pay to each other and display it"""
|
||||
return render_template("compute_bills.html")
|
||||
|
||||
@app.route("/<project_id>/archives/create")
|
||||
def create_archive():
|
||||
form = CreateArchiveForm()
|
||||
if request.method == "POST":
|
||||
if form.validate():
|
||||
pass
|
||||
flash("The data from XX to XX has been archived")
|
||||
|
||||
@app.route("/<project_id>/reset")
|
||||
def reset_bills():
|
||||
"""Reset the list of bills"""
|
||||
# FIXME replace with the archive feature
|
||||
# get all the bills which are not processed
|
||||
bills = Bill.query.filter(Bill.processed == False)
|
||||
for bill in bills:
|
||||
bill.processed = True
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for('list_bills'))
|
||||
return render_template("create_archive.html", form=form)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Reference in a new issue