28 lines
874 B
Python
28 lines
874 B
Python
from flask import Blueprint, render_template, redirect, url_for
|
|
from extensions import db
|
|
from models.quote import Quote
|
|
from models.invoice import Invoice
|
|
from models.payment import Payment
|
|
from services.invoicing import invoice_from_quote
|
|
|
|
bp = Blueprint("invoices", __name__, url_prefix="/invoices")
|
|
|
|
@bp.route("/")
|
|
def list_invoices():
|
|
return render_template("invoices/list.html", invoices=Invoice.query.all())
|
|
|
|
@bp.route("/from-quote/<int:quote_id>", methods=["POST"])
|
|
def create_from_quote(quote_id):
|
|
q = Quote.query.get_or_404(quote_id)
|
|
|
|
inv = invoice_from_quote(q)
|
|
db.session.add(inv)
|
|
db.session.commit()
|
|
|
|
return redirect(url_for("invoices.view_invoice", invoice_id=inv.id))
|
|
|
|
@bp.route("/<int:invoice_id>")
|
|
def view_invoice(invoice_id):
|
|
inv = Invoice.query.get_or_404(invoice_id)
|
|
return render_template("invoices/view.html", inv=inv)
|