From 3fe6919befe5987615b303f6140b413a124162c1 Mon Sep 17 00:00:00 2001 From: Mira Weller Date: Mon, 15 Jul 2024 09:40:53 +0200 Subject: [PATCH] add typing --- src/pretix/base/models/items.py | 15 +++++++-------- src/pretix/base/services/pricing.py | 2 +- src/pretix/presale/checkoutflow.py | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pretix/base/models/items.py b/src/pretix/base/models/items.py index 5ad7d02463..a256f9aa62 100644 --- a/src/pretix/base/models/items.py +++ b/src/pretix/base/models/items.py @@ -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 ) diff --git a/src/pretix/base/services/pricing.py b/src/pretix/base/services/pricing.py index 0ae892e765..83ba14d6ca 100644 --- a/src/pretix/base/services/pricing.py +++ b/src/pretix/base/services/pricing.py @@ -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]: """ diff --git a/src/pretix/presale/checkoutflow.py b/src/pretix/presale/checkoutflow.py index 977680da11..c7c2e7fd1d 100644 --- a/src/pretix/presale/checkoutflow.py +++ b/src/pretix/presale/checkoutflow.py @@ -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