Implement adding orders to the cart and viewing it
This commit is contained in:
parent
a4c5659701
commit
be53deb9ce
@ -210,19 +210,19 @@ view { globals, state } = case state of
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
ItemEditor model ->
|
ItemEditor model ->
|
||||||
Html.form [ method "POST", action "/entry/add-to-cart" ]
|
Html.form [ method "POST" ]
|
||||||
[ fieldset []
|
[ fieldset []
|
||||||
[ legend [] [ text "Neuer Inventareintrag" ]
|
[ legend [] [ text "Neuer Inventareintrag" ]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "barcode" ] [ text "Barcode" ]
|
[ 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" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "name" ] [ text "Name" ]
|
[ label [ for "name" ] [ text "Name" ]
|
||||||
, input [ onInput SetName, value model.name, name "name", id "name" ] []
|
, input [ onInput SetName, value model.name, name "name", id "name" ] []
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, 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" ] []
|
, input [ onInput SetSalesUnits, value <| NumberInput.show model.salesUnits, name "sales-units", id "sales-units", type_ "number" ] []
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
@ -264,7 +264,7 @@ view { globals, state } = case state of
|
|||||||
[]
|
[]
|
||||||
, viewSetSuggestedPriceButton model
|
, viewSetSuggestedPriceButton model
|
||||||
]
|
]
|
||||||
, button [] [ text "In den Warenkorb" ]
|
, button [] [ text "Auftrag anlegen" ]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
55
jon/entry.py
55
jon/entry.py
@ -7,8 +7,45 @@ from . import db
|
|||||||
bp = Blueprint("entry", __name__, url_prefix="/entry")
|
bp = Blueprint("entry", __name__, url_prefix="/entry")
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/")
|
@bp.route("/", methods=["GET", "POST"])
|
||||||
def index():
|
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:
|
with db.run_query("entry/get_groups.sql") as cursor:
|
||||||
groups = cursor.fetchall()
|
groups = cursor.fetchall()
|
||||||
|
|
||||||
@ -18,11 +55,17 @@ def index():
|
|||||||
with db.run_query("entry/get_tax_groups.sql") as cursor:
|
with db.run_query("entry/get_tax_groups.sql") as cursor:
|
||||||
tax_groups = cursor.fetchall()
|
tax_groups = cursor.fetchall()
|
||||||
|
|
||||||
return render_template("entry/index.html", **{
|
return render_template(
|
||||||
"locations": locations,
|
"entry/new-order.html",
|
||||||
"groups": groups,
|
groups=groups,
|
||||||
"tax_groups": tax_groups
|
locations=locations,
|
||||||
})
|
tax_groups=tax_groups
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# API routes for interactive JS stuff
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/api/search-items")
|
@bp.get("/api/search-items")
|
||||||
def api_search_items():
|
def api_search_items():
|
||||||
|
@ -11458,21 +11458,6 @@ var $author$project$Entry$SetTaxGroup = function (a) {
|
|||||||
return {$: 'SetTaxGroup', a: a};
|
return {$: 'SetTaxGroup', a: a};
|
||||||
};
|
};
|
||||||
var $author$project$Entry$SubmitSearch = {$: 'SubmitSearch'};
|
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$fieldset = _VirtualDom_node('fieldset');
|
||||||
var $elm$html$Html$Attributes$for = $elm$html$Html$Attributes$stringProperty('htmlFor');
|
var $elm$html$Html$Attributes$for = $elm$html$Html$Attributes$stringProperty('htmlFor');
|
||||||
var $elm$html$Html$form = _VirtualDom_node('form');
|
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) {
|
var $author$project$Calculator$SetTax = function (a) {
|
||||||
return {$: 'SetTax', a: 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 ($) {
|
var $author$project$NumberInput$get = function ($) {
|
||||||
return $.value;
|
return $.value;
|
||||||
};
|
};
|
||||||
@ -12009,8 +12003,7 @@ var $author$project$Entry$view = function (_v0) {
|
|||||||
$elm$html$Html$form,
|
$elm$html$Html$form,
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
[
|
[
|
||||||
$elm$html$Html$Attributes$method('POST'),
|
$elm$html$Html$Attributes$method('POST')
|
||||||
$elm$html$Html$Attributes$action('/entry/add-to-cart')
|
|
||||||
]),
|
]),
|
||||||
_List_fromArray(
|
_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$Events$onInput($author$project$Entry$SetBarcode),
|
||||||
$elm$html$Html$Attributes$value(model.barcode),
|
$elm$html$Html$Attributes$value(model.barcode),
|
||||||
$elm$html$Html$Attributes$disabled(true),
|
|
||||||
$elm$html$Html$Attributes$name('barcode'),
|
$elm$html$Html$Attributes$name('barcode'),
|
||||||
$elm$html$Html$Attributes$id('barcode')
|
$elm$html$Html$Attributes$id('barcode')
|
||||||
]),
|
]),
|
||||||
@ -12101,7 +12093,7 @@ var $author$project$Entry$view = function (_v0) {
|
|||||||
]),
|
]),
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
[
|
[
|
||||||
$elm$html$Html$text('Stückzahl')
|
$elm$html$Html$text('Eingekauft')
|
||||||
])),
|
])),
|
||||||
A2(
|
A2(
|
||||||
$elm$html$Html$input,
|
$elm$html$Html$input,
|
||||||
@ -12278,7 +12270,7 @@ var $author$project$Entry$view = function (_v0) {
|
|||||||
_List_Nil,
|
_List_Nil,
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
[
|
[
|
||||||
$elm$html$Html$text('In den Warenkorb')
|
$elm$html$Html$text('Auftrag anlegen')
|
||||||
]))
|
]))
|
||||||
]))
|
]))
|
||||||
]));
|
]));
|
||||||
|
@ -1,16 +1,30 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="entry-app"></div>
|
<a href="/entry/new-order">Neuer Auftrag</a>
|
||||||
<script src="{{ url_for('static', filename='entry.js') }}"></script>
|
<h2>Aufträge</h2>
|
||||||
<script>
|
<table>
|
||||||
Elm.Entry.init({
|
<tr>
|
||||||
node: document.querySelector('.entry-app'),
|
<th>Barcode</th>
|
||||||
flags: {
|
<th>Name</th>
|
||||||
locations: {{ to_json(locations) | safe }},
|
<th>Eingekauft</th>
|
||||||
groups: {{ to_json(groups) | safe }},
|
<th>Gruppen-ID</th>
|
||||||
taxGroups: {{ to_json(tax_groups) | safe }}
|
<th>Raum-ID</th>
|
||||||
}
|
<th>Steuergruppen-ID</th>
|
||||||
});
|
<th>EK-Preis (Netto)</th>
|
||||||
</script>
|
<th>VK-Preis (Brutto)</th>
|
||||||
|
</tr>
|
||||||
|
{% for cart_item in cart %}
|
||||||
|
<tr>
|
||||||
|
<td><code>{{ cart_item.barcode }}</code></td>
|
||||||
|
<td>{{ cart_item.name }}</td>
|
||||||
|
<td class="--align-right">{{ cart_item.sales_units }}</td>
|
||||||
|
<td class="--align-right">{{ cart_item.group_id }}</td>
|
||||||
|
<td class="--align-right">{{ cart_item.location_id }}</td>
|
||||||
|
<td class="--align-right">{{ cart_item.tax_group_id }}</td>
|
||||||
|
<td class="--align-right">{{ format_currency(cart_item.net_unit_price) }}</td>
|
||||||
|
<td class="--align-right">{{ format_currency(cart_item.gross_unit_price) }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
16
jon/templates/entry/new-order.html
Normal file
16
jon/templates/entry/new-order.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="entry-app"></div>
|
||||||
|
<script src="{{ url_for('static', filename='entry.js') }}"></script>
|
||||||
|
<script>
|
||||||
|
Elm.Entry.init({
|
||||||
|
node: document.querySelector('.entry-app'),
|
||||||
|
flags: {
|
||||||
|
locations: {{ to_json(locations) | safe }},
|
||||||
|
groups: {{ to_json(groups) | safe }},
|
||||||
|
taxGroups: {{ to_json(tax_groups) | safe }}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user