Add sales channels (#1103)

- [x] Data model
- [x] Enforce constraint
- [x] Filter order list
- [x] Set channel on created order
- [x] Products API
- [x] Order API
- [x] Tests
- [x] Filter reports
- [x] Resellers
- [ ] deploy plugins
  - [ ] posbackend
  - [ ] resellers
  - [ ] reports
- [x] Ticketlayouts
- [x] Support in pretixPOS
This commit is contained in:
Raphael Michel
2018-11-23 15:35:09 +01:00
committed by GitHub
parent 0f76779fb1
commit b4290384e1
39 changed files with 472 additions and 57 deletions

View File

@@ -236,7 +236,8 @@ class AddOnsStep(CartMixin, AsyncAction, TemplateFlowStep):
data=(self.request.POST if self.request.method == 'POST' else None),
quota_cache=quota_cache,
item_cache=item_cache,
subevent=cartpos.subevent
subevent=cartpos.subevent,
sales_channel=self.request.sales_channel
)
}
@@ -294,7 +295,8 @@ class AddOnsStep(CartMixin, AsyncAction, TemplateFlowStep):
return self.get(request, *args, **kwargs)
return self.do(self.request.event.id, data, get_or_create_cart_id(self.request),
invoice_address=self.invoice_address.pk, locale=get_language())
invoice_address=self.invoice_address.pk, locale=get_language(),
sales_channel=request.sales_channel)
class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
@@ -613,7 +615,8 @@ class ConfirmStep(CartMixin, AsyncAction, TemplateFlowStep):
return self.do(self.request.event.id, self.payment_provider.identifier if self.payment_provider else None,
[p.id for p in self.positions], self.cart_session.get('email'),
translation.get_language(), self.invoice_address.pk, meta_info)
translation.get_language(), self.invoice_address.pk, meta_info,
request.sales_channel)
def get_success_message(self, value):
create_empty_cart_id(self.request)

View File

@@ -138,7 +138,6 @@ class AddOnsForm(forms.Form):
if override_price:
price = override_price
print(price, repr(price), type(price), repr(item.default_price))
if self.price_included:
price = TAXED_ZERO
else:
@@ -191,6 +190,7 @@ class AddOnsForm(forms.Form):
quota_cache = kwargs.pop('quota_cache')
item_cache = kwargs.pop('item_cache')
self.price_included = kwargs.pop('price_included')
self.sales_channel = kwargs.pop('sales_channel')
super().__init__(*args, **kwargs)
@@ -209,6 +209,7 @@ class AddOnsForm(forms.Form):
& Q(Q(available_from__isnull=True) | Q(available_from__lte=now()))
& Q(Q(available_until__isnull=True) | Q(available_until__gte=now()))
& Q(hide_without_voucher=False)
& Q(sales_channels__contains=self.sales_channel)
).select_related('tax_rule').prefetch_related(
Prefetch('quotas',
to_attr='_subevent_quotas',

View File

@@ -92,6 +92,9 @@ def _detect_event(request, require_live=True, require_plugin=None):
if require_plugin not in request.event.get_plugins() and not is_core:
raise Http404(_('This feature is not enabled.'))
if not hasattr(request, 'sales_channel'):
# The environ lookup is only relevant during unit testing
request.sales_channel = request.environ.get('PRETIX_SALES_CHANNEL', 'web')
for receiver, response in process_request.send(request.event, request=request):
if response:
return response

View File

@@ -382,7 +382,7 @@ class CartAdd(EventViewMixin, CartActionMixin, AsyncAction, View):
items = self._items_from_post_data()
if items:
return self.do(self.request.event.id, items, cart_id, translation.get_language(),
self.invoice_address.pk, widget_data)
self.invoice_address.pk, widget_data, self.request.sales_channel)
else:
if 'ajax' in self.request.GET or 'ajax' in self.request.POST:
return JsonResponse({
@@ -405,7 +405,7 @@ class RedeemView(NoSearchIndexViewMixin, EventViewMixin, TemplateView):
# Fetch all items
items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent,
voucher=self.voucher)
voucher=self.voucher, channel=self.request.sales_channel)
# Calculate how many options the user still has. If there is only one option, we can
# check the box right away ;)

View File

@@ -47,12 +47,13 @@ def item_group_by_category(items):
)
def get_grouped_items(event, subevent=None, voucher=None):
def get_grouped_items(event, subevent=None, voucher=None, channel='web'):
items = event.items.all().filter(
Q(active=True)
& Q(Q(available_from__isnull=True) | Q(available_from__lte=now()))
& Q(Q(available_until__isnull=True) | Q(available_until__gte=now()))
& Q(Q(category__isnull=True) | Q(category__is_addon=False))
& Q(sales_channels__contains=channel)
)
vouchq = Q(hide_without_voucher=False)
@@ -249,7 +250,8 @@ class EventIndex(EventViewMixin, CartMixin, TemplateView):
context = super().get_context_data(**kwargs)
if not self.request.event.has_subevents or self.subevent:
# Fetch all items
items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent)
items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent,
channel=self.request.sales_channel)
context['itemnum'] = len(items)
# Regroup those by category

View File

@@ -155,7 +155,7 @@ class WidgetAPIProductList(View):
def _get_items(self):
items, display_add_to_cart = get_grouped_items(
self.request.event, subevent=self.subevent, voucher=self.voucher
self.request.event, subevent=self.subevent, voucher=self.voucher, channel='web'
)
grps = []
for cat, g in item_group_by_category(items):