mirror of
https://github.com/ae-utbm/sith.git
synced 2026-05-23 17:30:17 +00:00
exclude products over clic limit from eboutic
This commit is contained in:
@@ -187,9 +187,10 @@
|
||||
{% for price in prices %}
|
||||
<button
|
||||
id="{{ price.id }}"
|
||||
class="card product-button clickable shadow"
|
||||
class="card clickable shadow"
|
||||
:class="{selected: basket.some((i) => i.priceId === {{ price.id }})}"
|
||||
@click='addFromCatalog({{ price.id }}, {{ price.full_label|tojson }}, {{ price.amount }})'
|
||||
{% if price.sold_out %}disabled{% endif %}
|
||||
>
|
||||
{% if price.product.icon %}
|
||||
<img
|
||||
@@ -202,6 +203,9 @@
|
||||
{% endif %}
|
||||
<div class="card-content">
|
||||
<h4 class="card-title">{{ price.full_label }}</h4>
|
||||
{% if price.sold_out -%}
|
||||
<p><em>{% trans %}Product sold out{% endtrans %}</em></p>
|
||||
{%- endif %}
|
||||
<p>{{ price.amount }} €</p>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
+12
-5
@@ -33,7 +33,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.exceptions import SuspiciousOperation, ValidationError
|
||||
from django.db import DatabaseError, transaction
|
||||
from django.db.models import Subquery
|
||||
from django.db.models import Exists, OuterRef, Subquery
|
||||
from django.db.models.fields import forms
|
||||
from django.db.utils import cached_property
|
||||
from django.http import HttpResponse
|
||||
@@ -92,7 +92,9 @@ class EbouticMainView(LoginRequiredMixin, FormView):
|
||||
kwargs["form_kwargs"] = {
|
||||
"customer": self.customer,
|
||||
"counter": get_eboutic(),
|
||||
"allowed_prices": {price.id: price for price in self.prices},
|
||||
"allowed_prices": {
|
||||
price.id: price for price in self.prices if not price.sold_out
|
||||
},
|
||||
}
|
||||
return kwargs
|
||||
|
||||
@@ -118,9 +120,14 @@ class EbouticMainView(LoginRequiredMixin, FormView):
|
||||
|
||||
@cached_property
|
||||
def prices(self) -> list[Price]:
|
||||
return get_eboutic().get_prices_for(
|
||||
self.customer,
|
||||
order_by=["product__product_type__order", "product_id", "amount"],
|
||||
eboutic = get_eboutic()
|
||||
sold_out_subquery = ~Exists(
|
||||
eboutic.products.under_clic_limit().filter(id=OuterRef("product_id"))
|
||||
)
|
||||
return list(
|
||||
eboutic.get_prices_for(self.customer)
|
||||
.annotate(sold_out=sold_out_subquery)
|
||||
.order_by("product__product_type__order", "product_id", "amount")
|
||||
)
|
||||
|
||||
@cached_property
|
||||
|
||||
Reference in New Issue
Block a user