Warranties

This commit is contained in:
Emily 2019-05-27 15:54:05 +01:00
parent 3cd208beb4
commit bff0977c39
6 changed files with 111 additions and 9 deletions

View File

@ -21,6 +21,12 @@ class BillForm(Form):
kid = IntegerField(_("KID"), render_kw = FORM_RENDER_KW)
date_due = DateField(_("Date due"), render_kw = FORM_RENDER_KW)
class WarrantyForm(Form):
item = StringField(_("Item"), [validators.DataRequired()], render_kw = FORM_RENDER_KW)
date_from = DateField(_("Date of purchase"), render_kw = FORM_RENDER_KW)
date_to = DateField(_("Warranty duration"), render_kw = FORM_RENDER_KW)
sum = DecimalField(_("Sum"), render_kw = FORM_RENDER_KW)
class LoginForm(Form):
email = StringField(_("Email"), [
validators.DataRequired(),

View File

@ -2,7 +2,7 @@ from flask import render_template, url_for, request, redirect, flash, abort
from wtforms import Form, BooleanField, StringField, PasswordField, validators
import flask_login
from forms.login import LoginForm, RegisterForm, BillForm, User, register_account
from forms.login import LoginForm, RegisterForm, BillForm, WarrantyForm, User, register_account
from objects import glob # Global sharing of python objects in a manageable way
@ -54,12 +54,40 @@ def bills():
conn.close()
return render_template("pages/bills.html", data=data, form=form)
@glob.app.route("/warranties")
@glob.app.route("/warranties", methods = ["GET", "POST"])
@flask_login.login_required
def warranties():
return "Unimplemented"
form = WarrantyForm(request.form)
@glob.app.route("/receipts")
conn = glob.make_sql_connection()
cur = conn.cursor()
if request.method == "POST" and form.validate():
cur.execute("""
INSERT
INTO Garanti
VALUES (NULL, %s, %s, %s, %s, 1, %s)
""", (form.item.data, form.date_from.data, form.date_to.data, form.sum.data, flask_login.current_user.id))
conn.commit()
return redirect(url_for("bills"))
cur.execute("""
SELECT Vare, Kjøpsdato, Garantitil, Pris
FROM Garanti
WHERE BrukerID = %s
""", (flask_login.current_user.id,))
data = []
for row in cur:
data.append(row)
cur.close()
conn.close()
return render_template("pages/warranties.html", data=data, form=form)
@glob.app.route("/receipts", methods = ["GET", "POST"])
@flask_login.login_required
def receipts():
return "Unimplemented"

View File

@ -1,4 +1,4 @@
{% set title = "Bills" %}
{% set title = _("Bills") %}
{% extends "layout/dash.html" %}

View File

@ -1,4 +1,4 @@
{% set title = "Dashboard" %}
{% set title = _("Dashboard") %}
{% extends "layout/dash.html" %}

View File

@ -1,4 +1,4 @@
{% set title = "Dashboard" %}
{% set title = _("Receipts") %}
{% extends "layout/dash.html" %}

View File

@ -1,11 +1,79 @@
{% set title = "Dashboard" %}
{% set title = _("Warranties") %}
{% extends "layout/dash.html" %}
{% block content %}
<style id="grid">
.container.module:nth-child(1n) {
grid-area: 1 / 1 / 5 / 5;
}
</style>
<div class="container module">
{% include "modules/calendar.html" %}
<button type="button" class="btn btn-primary" style="margin:10px;" data-toggle="modal" data-target="#myModal">{{ _("Add") }}</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{ _("Add warrenty") }}</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
{% macro render_field(field) %}
<div class="form-group">
<label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label>
{{ field(**kwargs)|safe }}
{% if field.errors %}
<ul class=errors>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endmacro %}
<form method=post>
<dl>
{{ render_field(form.item) }}
{{ render_field(form.date_from) }}
{{ render_field(form.date_to) }}
{{ render_field(form.sum) }}
</dl>
<input type=submit value="{{ _('Add') }}">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ _("Close") }}</button>
</div>
</div>
</div>
</div>
<table class="table">
<thead class="thead-light">
<tr>
<th scope="col">{{ _("Item") }}</th>
<th scope="col" style="width: 140px">{{ _("Date of purchase") }}</th>
<th scope="col" style="width: 140px">{{ _("Warranty duration") }}</th>
<th scope="col" style="width: 140px">{{ _("Sum") }}</th>
</tr>
</thead>
<tbody>
{% for row in data %}
<!--<tr class="table-{{ 'success' if row[5] else 'danger' }}">-->
<tr>
<th>{{ row[0] }}</th>
<td>{{ row[1] }}</td>
<td>{{ row[2] }}</td>
<td>{{ row[3] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}