From 372470b44b711d9c0dd84d1e6241359a73d4e8c2 Mon Sep 17 00:00:00 2001 From: Sli Date: Sun, 22 Dec 2024 12:00:42 +0100 Subject: [PATCH] Improve empty basket and tray price management --- .../static/bundled/counter/counter-click-index.ts | 12 +++++++----- counter/templates/counter/counter_click.jinja | 8 +++++--- counter/views/click.py | 12 +++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/counter/static/bundled/counter/counter-click-index.ts b/counter/static/bundled/counter/counter-click-index.ts index e05de762..f7886bee 100644 --- a/counter/static/bundled/counter/counter-click-index.ts +++ b/counter/static/bundled/counter/counter-click-index.ts @@ -1,10 +1,8 @@ import { exportToHtml } from "#core:utils/globals"; -const quantityForTrayPrice = 6; - interface InitialFormData { /* Used to refill the form when the backend raises an error */ - id?: string; + id?: Pick; quantity?: number; errors?: string[]; } @@ -23,11 +21,13 @@ interface Product { name: string; price: number; hasTrayPrice: boolean; + quantityForTrayPrice: number; } class BasketItem { quantity: number; product: Product; + quantityForTrayPrice: number; errors: string[]; constructor(product: Product, quantity: number) { @@ -40,7 +40,7 @@ class BasketItem { if (!this.product.hasTrayPrice) { return 0; } - return Math.floor(this.quantity / quantityForTrayPrice); + return Math.floor(this.quantity / this.product.quantityForTrayPrice); } sum(): number { @@ -127,7 +127,9 @@ exportToHtml("loadCounter", (config: CounterConfig) => { }, finish() { - this.$refs.basketForm.submit(); + if (this.getBasketSize() > 0) { + this.$refs.basketForm.submit(); + } }, cancel() { diff --git a/counter/templates/counter/counter_click.jinja b/counter/templates/counter/counter_click.jinja index 96a4b0e2..1a5f6d9e 100644 --- a/counter/templates/counter/counter_click.jinja +++ b/counter/templates/counter/counter_click.jinja @@ -79,11 +79,12 @@ {% endfor %}

{% trans %}Basket: {% endtrans %}

-
+ {% csrf_token %}
{{ form.management_form }}
+
    {% trans %}This basket is empty{% endtrans %}