mirror of
https://github.com/ae-utbm/sith.git
synced 2026-03-14 07:35:00 +00:00
unify eboutic and regular counter price selection
This commit is contained in:
@@ -22,7 +22,7 @@ from typing import Self
|
||||
from dict2xml import dict2xml
|
||||
from django.conf import settings
|
||||
from django.db import DataError, models
|
||||
from django.db.models import F, OuterRef, Q, Subquery, Sum
|
||||
from django.db.models import F, OuterRef, Subquery, Sum
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@@ -39,30 +39,6 @@ from counter.models import (
|
||||
)
|
||||
|
||||
|
||||
def get_eboutic_prices(user: User) -> list[Price]:
|
||||
return list(
|
||||
Price.objects.filter(
|
||||
Q(is_always_shown=True, groups__in=user.all_groups)
|
||||
| Q(
|
||||
id=Subquery(
|
||||
Price.objects.filter(
|
||||
product_id=OuterRef("product_id"), groups__in=user.all_groups
|
||||
)
|
||||
.order_by("amount")
|
||||
.values("id")[:1]
|
||||
)
|
||||
),
|
||||
product__product_type__isnull=False,
|
||||
product__archived=False,
|
||||
product__limit_age__lte=user.age,
|
||||
product__counters=get_eboutic(),
|
||||
)
|
||||
.select_related("product", "product__product_type")
|
||||
.order_by("product__product_type__order", "product_id", "amount")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
|
||||
class BillingInfoState(Enum):
|
||||
VALID = 1
|
||||
EMPTY = 2
|
||||
|
||||
@@ -29,9 +29,7 @@ from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import (
|
||||
LoginRequiredMixin,
|
||||
)
|
||||
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
|
||||
@@ -58,14 +56,7 @@ from counter.models import (
|
||||
Selling,
|
||||
get_eboutic,
|
||||
)
|
||||
from eboutic.models import (
|
||||
Basket,
|
||||
BasketItem,
|
||||
BillingInfoState,
|
||||
Invoice,
|
||||
InvoiceItem,
|
||||
get_eboutic_prices,
|
||||
)
|
||||
from eboutic.models import Basket, BasketItem, BillingInfoState, Invoice, InvoiceItem
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
|
||||
@@ -125,7 +116,10 @@ class EbouticMainView(LoginRequiredMixin, FormView):
|
||||
|
||||
@cached_property
|
||||
def prices(self) -> list[Price]:
|
||||
return get_eboutic_prices(self.request.user)
|
||||
return get_eboutic().get_prices_for(
|
||||
self.customer,
|
||||
order_by=["product__product_type__order", "product_id", "amount"],
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def customer(self) -> Customer:
|
||||
|
||||
Reference in New Issue
Block a user