Fix #1111 -- Duplicate voucher warning (#1142)

Adds a new method to Voucher that selects all distinct orders containing
a position where the Voucher has been used, and changes the Voucher
detail view to use this method for the warning.
This commit is contained in:
Maarten van den Berg
2019-01-21 08:52:31 +01:00
committed by Raphael Michel
parent 350df2a3cc
commit bf1e9d47d0
3 changed files with 51 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ from ..decimal import round_decimal
from .base import LoggedModel
from .event import Event, SubEvent
from .items import Item, ItemVariation, Quota
from .orders import Order
def _generate_random_code(prefix=None):
@@ -380,3 +381,11 @@ class Voucher(LoggedModel):
return p.quantize(Decimal('1') / 10 ** places, ROUND_HALF_UP)
return p
return original_price
def distinct_orders(self):
"""
Return the list of orders where this voucher has been used.
Each order will appear at most once.
"""
return Order.objects.filter(all_positions__voucher__in=[self]).distinct()