Fix unpriced item deletion

This commit is contained in:
Gabriel Augendre 2023-03-27 16:49:26 +02:00
parent 56c2c7045d
commit f3cd4201b2
2 changed files with 8 additions and 3 deletions

View file

@ -14,7 +14,7 @@
<div class="card-body">
<h4 class="card-title">{{ product.name }}</h4>
<div class="input-group">
<input type="number" step="0.01" name="unpriced_product-{{ product.pk }}" min="0" class="numberinput form-control" required="" id="unpriced_id_product-{{ product.pk }}"
<input type="number" step="1" name="unpriced_product-{{ product.pk }}" min="0" class="numberinput form-control" required="" id="unpriced_id_product-{{ product.pk }}"
value="{{ value|default:0 }}"
>
</div>

View file

@ -49,8 +49,13 @@ def update_with_unpriced_products(basket: Basket, post_data: MultiValueDict):
basket.items.filter(product__in=no_fixed_price.values()).delete()
for product_id, product in no_fixed_price.items():
if prices := post_data.getlist(f"{UNPRICED_PREFIX}{product_id}"):
for price in prices:
basket.items.create(product=product, quantity=1, unit_price_cents=price)
for price in map(int, prices):
if price:
basket.items.create(
product=product,
quantity=1,
unit_price_cents=price,
)
@require_http_methods(["GET", "POST"])