Make it possible to delete orders from the cart

This commit is contained in:
Paul Brinkmeier 2023-08-20 20:08:24 +02:00
parent be53deb9ce
commit 4324311441
4 changed files with 25 additions and 4 deletions

View File

@ -200,7 +200,7 @@ suggestedGrossPrice netPrice percentage =
view { globals, state } = case state of view { globals, state } = case state of
ItemSearch model -> ItemSearch model ->
fieldset [] fieldset []
[ legend [] [ text "Vorlage für neuen Inventareintrag" ] [ legend [] [ text "Vorlage für Auftrag wählen" ]
, Html.form [ onSubmit SubmitSearch ] , Html.form [ onSubmit SubmitSearch ]
[ div [ class "form-input" ] [ div [ class "form-input" ]
[ label [ for "search-term", title "Barcode oder Name" ] [ text "Suchbegriff" ] [ label [ for "search-term", title "Barcode oder Name" ] [ text "Suchbegriff" ]

View File

@ -9,13 +9,27 @@ bp = Blueprint("entry", __name__, url_prefix="/entry")
@bp.route("/", methods=["GET", "POST"]) @bp.route("/", methods=["GET", "POST"])
def index(): def index():
cart = session["cart"] cart = session.get("cart", default=[])
return render_template( return render_template(
"entry/index.html", "entry/index.html",
cart=cart cart=cart
) )
@bp.post("/delete-order")
def delete_order():
try:
order_index = int(request.form["order-index"])
except:
return f"Incomplete or mistyped form", 400
cart = session.get("cart", default=[])
del cart[order_index]
session["cart"] = cart
return redirect(request.referrer)
@bp.route("/new-order", methods=["GET", "POST"]) @bp.route("/new-order", methods=["GET", "POST"])
def new_order(): def new_order():
if request.method == "POST": if request.method == "POST":
@ -28,7 +42,7 @@ def new_order():
tax_group_id = int(request.form["tax-group"]) tax_group_id = int(request.form["tax-group"])
net_unit_price = float(request.form["net-unit-price"]) net_unit_price = float(request.form["net-unit-price"])
gross_unit_price = float(request.form["gross-unit-price"]) gross_unit_price = float(request.form["gross-unit-price"])
except Exception as e: except:
return f"Incomplete or mistyped form", 400 return f"Incomplete or mistyped form", 400
cart = session.get("cart", default=[]) cart = session.get("cart", default=[])

View File

@ -11949,7 +11949,7 @@ var $author$project$Entry$view = function (_v0) {
_List_Nil, _List_Nil,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$text('Vorlage für neuen Inventareintrag') $elm$html$Html$text('Vorlage für Auftrag wählen')
])), ])),
A2( A2(
$elm$html$Html$form, $elm$html$Html$form,

View File

@ -13,6 +13,7 @@
<th>Steuergruppen-ID</th> <th>Steuergruppen-ID</th>
<th>EK-Preis (Netto)</th> <th>EK-Preis (Netto)</th>
<th>VK-Preis (Brutto)</th> <th>VK-Preis (Brutto)</th>
<th>Aktionen</th>
</tr> </tr>
{% for cart_item in cart %} {% for cart_item in cart %}
<tr> <tr>
@ -24,6 +25,12 @@
<td class="--align-right">{{ cart_item.tax_group_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.net_unit_price) }}</td>
<td class="--align-right">{{ format_currency(cart_item.gross_unit_price) }}</td> <td class="--align-right">{{ format_currency(cart_item.gross_unit_price) }}</td>
<td>
<form method="POST" action="/entry/delete-order">
<input type="hidden" name="order-index" value="{{ loop.index0 }}">
<button>Löschen</button>
</form>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>