60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
import datetime
|
|
import zoneinfo
|
|
|
|
|
|
from flask import Blueprint, redirect, render_template, request, session
|
|
|
|
from . import db
|
|
|
|
|
|
bp = Blueprint("entry", __name__, url_prefix="/entry")
|
|
|
|
|
|
@bp.get("/")
|
|
def index():
|
|
return render_template("entry/index.html")
|
|
|
|
|
|
@bp.route("/edit-item-data", methods=["GET", "POST"])
|
|
def edit_item_data():
|
|
if "entry" not in session:
|
|
session["entry"] = dict()
|
|
|
|
if request.method == "POST":
|
|
session["entry"] = {
|
|
"item_bought": datetime.datetime.strptime(request.form.get("item_bought"), "%Y-%m-%d"),
|
|
"item_barcode": request.form.get("item_barcode"),
|
|
"item_name": request.form.get("item_name"),
|
|
"item_group_id": int(request.form.get("item_group")),
|
|
"item_net_unit_price": float(request.form.get("item_net_unit_price")),
|
|
"item_tax_group_id": int(request.form.get("item_tax_group")),
|
|
"item_amount": int(request.form.get("item_amount")),
|
|
"item_location_id": int(request.form.get("item_location"))
|
|
}
|
|
|
|
return redirect("/entry/select-snack-entry")
|
|
|
|
groups = db.run_query("get_groups.sql").fetchall()
|
|
locations = db.run_query("get_locations.sql").fetchall()
|
|
|
|
return render_template("entry/edit-item-data.html", **{
|
|
"groups": groups,
|
|
"locations": locations,
|
|
"entry": session["entry"]
|
|
})
|
|
|
|
|
|
@bp.route("/select-snack-entry", methods=["GET", "POST"])
|
|
def edit_snack_data():
|
|
if "entry" not in session:
|
|
return redirect("/entry/edit-item-data")
|
|
|
|
snacks = db.run_query("get_snacks_by_barcode.sql", {
|
|
"snack_barcode": session["entry"]["item_barcode"]
|
|
}).fetchall()
|
|
|
|
return render_template("entry/select-snack-entry.html", **{
|
|
"entry": session["entry"],
|
|
"snacks": snacks
|
|
})
|