diff --git a/frontend/Entry.elm b/frontend/Entry.elm index b512f26..503fe4e 100644 --- a/frontend/Entry.elm +++ b/frontend/Entry.elm @@ -210,19 +210,19 @@ view { globals, state } = case state of ] ] ItemEditor model -> - Html.form [ method "POST", action "/entry/add-to-cart" ] + Html.form [ method "POST" ] [ fieldset [] [ legend [] [ text "Neuer Inventareintrag" ] , div [ class "form-input" ] [ label [ for "barcode" ] [ text "Barcode" ] - , input [ onInput SetBarcode, value model.barcode, disabled True, name "barcode", id "barcode" ] [] + , input [ onInput SetBarcode, value model.barcode, name "barcode", id "barcode" ] [] ] , div [ class "form-input" ] [ label [ for "name" ] [ text "Name" ] , input [ onInput SetName, value model.name, name "name", id "name" ] [] ] , div [ class "form-input" ] - [ label [ for "sales-units" ] [ text "Stückzahl" ] + [ label [ for "sales-units" ] [ text "Eingekauft" ] , input [ onInput SetSalesUnits, value <| NumberInput.show model.salesUnits, name "sales-units", id "sales-units", type_ "number" ] [] ] , div [ class "form-input" ] @@ -264,7 +264,7 @@ view { globals, state } = case state of [] , viewSetSuggestedPriceButton model ] - , button [] [ text "In den Warenkorb" ] + , button [] [ text "Auftrag anlegen" ] ] ] diff --git a/jon/entry.py b/jon/entry.py index 4ab298b..c3b6a8d 100644 --- a/jon/entry.py +++ b/jon/entry.py @@ -7,8 +7,45 @@ from . import db bp = Blueprint("entry", __name__, url_prefix="/entry") -@bp.get("/") +@bp.route("/", methods=["GET", "POST"]) def index(): + cart = session["cart"] + return render_template( + "entry/index.html", + cart=cart + ) + + +@bp.route("/new-order", methods=["GET", "POST"]) +def new_order(): + if request.method == "POST": + try: + barcode = request.form["barcode"] + name = request.form["name"] + sales_units = int(request.form["sales-units"]) + group_id = int(request.form["group"]) + location_id = int(request.form["location"]) + tax_group_id = int(request.form["tax-group"]) + net_unit_price = float(request.form["net-unit-price"]) + gross_unit_price = float(request.form["gross-unit-price"]) + except Exception as e: + return f"Incomplete or mistyped form", 400 + + cart = session.get("cart", default=[]) + print(cart) + cart.append({ + "barcode": barcode, + "name": name, + "sales_units": sales_units, + "group_id": group_id, + "location_id": location_id, + "tax_group_id": tax_group_id, + "net_unit_price": net_unit_price, + "gross_unit_price": gross_unit_price + }) + session["cart"] = cart + return redirect("/entry") + with db.run_query("entry/get_groups.sql") as cursor: groups = cursor.fetchall() @@ -18,11 +55,17 @@ def index(): with db.run_query("entry/get_tax_groups.sql") as cursor: tax_groups = cursor.fetchall() - return render_template("entry/index.html", **{ - "locations": locations, - "groups": groups, - "tax_groups": tax_groups - }) + return render_template( + "entry/new-order.html", + groups=groups, + locations=locations, + tax_groups=tax_groups + ) + + + +# API routes for interactive JS stuff + @bp.get("/api/search-items") def api_search_items(): diff --git a/jon/static/entry.js b/jon/static/entry.js index f42209a..f5720f3 100644 --- a/jon/static/entry.js +++ b/jon/static/entry.js @@ -11458,21 +11458,6 @@ var $author$project$Entry$SetTaxGroup = function (a) { return {$: 'SetTaxGroup', a: a}; }; var $author$project$Entry$SubmitSearch = {$: 'SubmitSearch'}; -var $elm$html$Html$Attributes$action = function (uri) { - return A2( - $elm$html$Html$Attributes$stringProperty, - 'action', - _VirtualDom_noJavaScriptUri(uri)); -}; -var $elm$json$Json$Encode$bool = _Json_wrap; -var $elm$html$Html$Attributes$boolProperty = F2( - function (key, bool) { - return A2( - _VirtualDom_property, - key, - $elm$json$Json$Encode$bool(bool)); - }); -var $elm$html$Html$Attributes$disabled = $elm$html$Html$Attributes$boolProperty('disabled'); var $elm$html$Html$fieldset = _VirtualDom_node('fieldset'); var $elm$html$Html$Attributes$for = $elm$html$Html$Attributes$stringProperty('htmlFor'); var $elm$html$Html$form = _VirtualDom_node('form'); @@ -11586,6 +11571,15 @@ var $author$project$Calculator$SetBundleSize = function (a) { var $author$project$Calculator$SetTax = function (a) { return {$: 'SetTax', a: a}; }; +var $elm$json$Json$Encode$bool = _Json_wrap; +var $elm$html$Html$Attributes$boolProperty = F2( + function (key, bool) { + return A2( + _VirtualDom_property, + key, + $elm$json$Json$Encode$bool(bool)); + }); +var $elm$html$Html$Attributes$disabled = $elm$html$Html$Attributes$boolProperty('disabled'); var $author$project$NumberInput$get = function ($) { return $.value; }; @@ -12009,8 +12003,7 @@ var $author$project$Entry$view = function (_v0) { $elm$html$Html$form, _List_fromArray( [ - $elm$html$Html$Attributes$method('POST'), - $elm$html$Html$Attributes$action('/entry/add-to-cart') + $elm$html$Html$Attributes$method('POST') ]), _List_fromArray( [ @@ -12050,7 +12043,6 @@ var $author$project$Entry$view = function (_v0) { [ $elm$html$Html$Events$onInput($author$project$Entry$SetBarcode), $elm$html$Html$Attributes$value(model.barcode), - $elm$html$Html$Attributes$disabled(true), $elm$html$Html$Attributes$name('barcode'), $elm$html$Html$Attributes$id('barcode') ]), @@ -12101,7 +12093,7 @@ var $author$project$Entry$view = function (_v0) { ]), _List_fromArray( [ - $elm$html$Html$text('Stückzahl') + $elm$html$Html$text('Eingekauft') ])), A2( $elm$html$Html$input, @@ -12278,7 +12270,7 @@ var $author$project$Entry$view = function (_v0) { _List_Nil, _List_fromArray( [ - $elm$html$Html$text('In den Warenkorb') + $elm$html$Html$text('Auftrag anlegen') ])) ])) ])); diff --git a/jon/templates/entry/index.html b/jon/templates/entry/index.html index b986866..6e9de2f 100644 --- a/jon/templates/entry/index.html +++ b/jon/templates/entry/index.html @@ -1,16 +1,30 @@ {% extends "base.html" %} {% block content %} -
- - +Neuer Auftrag +

Aufträge

+ + + + + + + + + + + + {% for cart_item in cart %} + + + + + + + + + + + {% endfor %} +
BarcodeNameEingekauftGruppen-IDRaum-IDSteuergruppen-IDEK-Preis (Netto)VK-Preis (Brutto)
{{ cart_item.barcode }}{{ cart_item.name }}{{ cart_item.sales_units }}{{ cart_item.group_id }}{{ cart_item.location_id }}{{ cart_item.tax_group_id }}{{ format_currency(cart_item.net_unit_price) }}{{ format_currency(cart_item.gross_unit_price) }}
{% endblock %} diff --git a/jon/templates/entry/new-order.html b/jon/templates/entry/new-order.html new file mode 100644 index 0000000..b986866 --- /dev/null +++ b/jon/templates/entry/new-order.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block content %} +
+ + +{% endblock %}