mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
add typing
This commit is contained in:
@@ -42,7 +42,7 @@ from collections import Counter, OrderedDict, defaultdict
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from decimal import Decimal, DecimalException
|
||||
from itertools import groupby
|
||||
from typing import Optional, Tuple
|
||||
from typing import List, Optional, Tuple
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import dateutil.parser
|
||||
@@ -64,14 +64,13 @@ from django_countries.fields import Country
|
||||
from django_scopes import ScopedManager
|
||||
from i18nfield.fields import I18nCharField, I18nTextField
|
||||
|
||||
from pretix.base.media import MEDIA_TYPES
|
||||
from pretix.base.models import CartPosition, Event, SalesChannel, SubEvent
|
||||
from pretix.base.models.base import LoggedModel
|
||||
from pretix.base.models.fields import MultiStringField
|
||||
from pretix.base.models.tax import TaxedPrice
|
||||
from pretix.base.timemachine import time_machine_now
|
||||
|
||||
from ...helpers.images import ImageSizeValidator
|
||||
from ..media import MEDIA_TYPES
|
||||
from .event import Event, SubEvent
|
||||
from pretix.helpers.images import ImageSizeValidator
|
||||
|
||||
|
||||
class ItemCategory(LoggedModel):
|
||||
@@ -145,7 +144,7 @@ class ItemCategory(LoggedModel):
|
||||
verbose_name_plural = _("Product categories")
|
||||
ordering = ('position', 'id')
|
||||
|
||||
def cross_sell_visible(self, cart, sales_channel):
|
||||
def cross_sell_visible(self, cartpositions: List[CartPosition], sales_channel: SalesChannel):
|
||||
"""
|
||||
If this category should be visible in the cross-selling step for a given cart and sales_channel, this method
|
||||
returns a queryset of the items that should be displayed, as well as a dict giving additional information on them.
|
||||
@@ -160,7 +159,7 @@ class ItemCategory(LoggedModel):
|
||||
return self.items.all(), {}
|
||||
if self.cross_selling_condition == 'products':
|
||||
match = set(match.pk for match in self.cross_selling_match_products.only('pk')) # TODO prefetch this
|
||||
return (self.items.all(), {}) if any(pos.item.pk in match for pos in cart) else (None, {})
|
||||
return (self.items.all(), {}) if any(pos.item.pk in match for pos in cartpositions) else (None, {})
|
||||
if self.cross_selling_condition == 'discounts':
|
||||
if not hasattr(self.event, '_potential_discounts_by_item_for_current_cart'):
|
||||
potential_discounts_by_cartpos = defaultdict(list)
|
||||
@@ -172,7 +171,7 @@ class ItemCategory(LoggedModel):
|
||||
[
|
||||
(cp.item_id, cp.subevent_id, cp.line_price_gross, bool(cp.addon_to), cp.is_bundled,
|
||||
cp.listed_price - cp.price_after_voucher)
|
||||
for cp in cart
|
||||
for cp in cartpositions
|
||||
],
|
||||
collect_potential_discounts=potential_discounts_by_cartpos
|
||||
)
|
||||
|
||||
@@ -156,7 +156,7 @@ def get_line_price(price_after_voucher: Decimal, custom_price_input: Decimal, cu
|
||||
return price
|
||||
|
||||
|
||||
def apply_discounts(event: Event, sales_channel: str,
|
||||
def apply_discounts(event: Event, sales_channel: str | SalesChannel,
|
||||
positions: List[Tuple[int, Optional[int], Decimal, bool, bool, Decimal]],
|
||||
collect_potential_discounts=None) -> List[Decimal]:
|
||||
"""
|
||||
|
||||
@@ -57,7 +57,7 @@ from django.views.generic.base import TemplateResponseMixin
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from pretix.base.models import Customer, Membership, Order
|
||||
from pretix.base.models.items import Question, ItemCategory
|
||||
from pretix.base.models.items import ItemCategory, Question
|
||||
from pretix.base.models.orders import (
|
||||
InvoiceAddress, OrderPayment, QuestionAnswer,
|
||||
)
|
||||
@@ -632,11 +632,11 @@ class AddOnsStep(CartMixin, AsyncAction, TemplateFlowStep):
|
||||
|
||||
@property
|
||||
def cross_selling_applicable_categories(self):
|
||||
cart = self.positions
|
||||
cartpositions = self.positions
|
||||
return [
|
||||
(c, products_qs, discount_info) for (c, products_qs, discount_info) in
|
||||
(
|
||||
(c, *c.cross_sell_visible(cart, self.request.sales_channel.identifier))
|
||||
(c, *c.cross_sell_visible(cartpositions, self.request.sales_channel.identifier))
|
||||
for c in self.request.event.categories.filter(cross_selling_mode__isnull=False)
|
||||
)
|
||||
if products_qs is not None
|
||||
|
||||
Reference in New Issue
Block a user