mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Refs #105 -- Variation support for vouchers
This commit is contained in:
21
src/pretix/base/migrations/0016_voucher_variation.py
Normal file
21
src/pretix/base/migrations/0016_voucher_variation.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.2 on 2016-03-20 10:14
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pretixbase', '0015_auto_20160312_1924'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='voucher',
|
||||
name='variation',
|
||||
field=models.ForeignKey(blank=True, help_text='This variation of the product select above is being used.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='vouchers', to='pretixbase.ItemVariation', verbose_name='Product variation'),
|
||||
),
|
||||
]
|
||||
@@ -493,17 +493,18 @@ class Quota(LoggedModel):
|
||||
def count_blocking_vouchers(self) -> int:
|
||||
from pretix.base.models import Voucher
|
||||
return Voucher.objects.filter(
|
||||
item__quotas__in=[self],
|
||||
block_quota=True,
|
||||
redeemed=False
|
||||
Q(item__quotas__in=[self]) &
|
||||
Q(block_quota=True) &
|
||||
Q(redeemed=False) &
|
||||
self._position_lookup
|
||||
).count()
|
||||
|
||||
def count_in_cart(self) -> int:
|
||||
from pretix.base.models import CartPosition
|
||||
|
||||
return CartPosition.objects.filter(
|
||||
Q(expires__gte=now())
|
||||
& self._position_lookup
|
||||
Q(expires__gte=now()) &
|
||||
self._position_lookup
|
||||
).count()
|
||||
|
||||
def count_orders(self) -> dict:
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .base import LoggedModel
|
||||
from .event import Event
|
||||
from .items import Item
|
||||
from .items import Item, ItemVariation
|
||||
from .orders import CartPosition, OrderPosition
|
||||
|
||||
|
||||
@@ -63,6 +63,14 @@ class Voucher(LoggedModel):
|
||||
"This product is added to the user's cart if the voucher is redeemed."
|
||||
)
|
||||
)
|
||||
variation = models.ForeignKey(
|
||||
ItemVariation, related_name='vouchers',
|
||||
null=True, blank=True,
|
||||
verbose_name=_("Product variation"),
|
||||
help_text=_(
|
||||
"This variation of the product select above is being used."
|
||||
)
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Voucher")
|
||||
|
||||
@@ -153,7 +153,7 @@ def _add_voucher(event: Event, voucher: str, expiry: datetime, cart_id: str):
|
||||
raise CartError(error_messages['unavailable'])
|
||||
|
||||
CartPosition.objects.create(
|
||||
event=event, item=v.item, variation=None,
|
||||
event=event, item=v.item, variation=v.variation,
|
||||
price=v.price if v.price is not None else v.item.default_price,
|
||||
expires=expiry, cart_id=cart_id, voucher=v
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user