diff options
author | Marius Peter <marius.peter@tutanota.com> | 2022-05-15 13:17:35 +0200 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2022-05-15 13:17:35 +0200 |
commit | e084f90c19e779592f6e3f14eb8f70a7287f0dad (patch) | |
tree | 1215177356105452c39a916fd050f79c9721f523 /app/modules/invoices | |
parent | 1dad22d3e45d6506c8624e3a7111240fcc4ab786 (diff) |
Modularization.
Diffstat (limited to 'app/modules/invoices')
-rw-r--r-- | app/modules/invoices/forms.py | 33 | ||||
-rw-r--r-- | app/modules/invoices/routes.py | 47 |
2 files changed, 80 insertions, 0 deletions
diff --git a/app/modules/invoices/forms.py b/app/modules/invoices/forms.py new file mode 100644 index 0000000..8ef7bd0 --- /dev/null +++ b/app/modules/invoices/forms.py @@ -0,0 +1,33 @@ +from flask_wtf import FlaskForm +from wtforms import ( + SubmitField, + SelectField, + HiddenField, + StringField, + PasswordField, + IntegerField, + FloatField, + BooleanField, + DateTimeField, +) +from wtforms.validators import InputRequired, Length, NumberRange + +from ...models import Customer + + +class AddInvoice(FlaskForm): + customer_id = SelectField("Customer", choices=[]) + invoice_id_alt = StringField("Alternative invoice ID") + customer_reference = StringField("Customer reference") + date_billed = StringField("Date billed") + date_due = StringField("Date due") + amount_net = FloatField("Amount without tax", default=0) + amount_gross = FloatField("Amount with tax", default=0) + amount_tax = FloatField("Amount of tax", default=0) + submit = SubmitField("Add new Invoice") + + def __init__(self, **kwargs): + super().__init__() + self.customer_id.choices = [ + (cus.primary_key, cus.name) for cus in Customer.query.all() + ] diff --git a/app/modules/invoices/routes.py b/app/modules/invoices/routes.py new file mode 100644 index 0000000..b8a0a68 --- /dev/null +++ b/app/modules/invoices/routes.py @@ -0,0 +1,47 @@ +# -*- mode: python; -*- + + +from flask import ( + Blueprint, + render_template, + send_file, + request, + redirect, + flash, + url_for, + jsonify, + abort, +) +from flask_login import login_required, current_user + + +from ... import db +from ...models import * +from .forms import * + + +invoices = Blueprint("invoices", __name__) + + + +@invoices.route("/modules/invoices") +@login_required +def view(): + modules = Module.query.all() + page = request.args.get('page', 1, type=int) + invoices = Invoice.query.order_by(Invoice.primary_key.desc()).paginate(page=page, per_page=5) + module = "invoices" + flash(f"Successfully accessed module {module}.", "info") + flash(f"Still fighting against styling in {module}.", "error") + return render_template( + f"modules/{module}.html", + modules=modules, + invoices=invoices, + ) + + +@invoices.route("/modules/invoices/preview/<int:pk>") +@login_required +def preview(pk): + invoice = Invoice.query.filter_by(primary_key=pk).first() + return render_template("modules/invoice-preview.html", invoice=invoice) |