mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
API/Vouchers: Expose "budget" and "budget_used" (Z#286557) (#5325)
Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
from decimal import Decimal
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
@@ -64,14 +66,15 @@ class SeatGuidField(serializers.CharField):
|
||||
|
||||
class VoucherSerializer(I18nAwareModelSerializer):
|
||||
seat = SeatGuidField(allow_null=True, required=False)
|
||||
budget_used = serializers.DecimalField(read_only=True, max_digits=13, decimal_places=2, min_value=Decimal('0.00'))
|
||||
|
||||
class Meta:
|
||||
model = Voucher
|
||||
fields = ('id', 'code', 'max_usages', 'redeemed', 'min_usages', 'valid_until', 'block_quota',
|
||||
'allow_ignore_quota', 'price_mode', 'value', 'item', 'variation', 'quota',
|
||||
'tag', 'comment', 'subevent', 'show_hidden_items', 'seat', 'all_addons_included',
|
||||
'all_bundles_included')
|
||||
read_only_fields = ('id', 'redeemed')
|
||||
'all_bundles_included', 'budget', 'budget_used')
|
||||
read_only_fields = ('id', 'redeemed', 'budget_used')
|
||||
list_serializer_class = VoucherListSerializer
|
||||
|
||||
def validate(self, data):
|
||||
|
||||
@@ -1750,7 +1750,7 @@ def test_event_expand_seat_filter_and_querycount(token_client, organizer, event,
|
||||
with scope(organizer=organizer):
|
||||
v0 = event.vouchers.create(item=item, seat=event.seats.get(seat_guid='0-0'))
|
||||
|
||||
with assert_num_queries(13):
|
||||
with assert_num_queries(14):
|
||||
resp = token_client.get('/api/v1/organizers/{}/events/{}/seats/'
|
||||
'?expand=orderposition&expand=cartposition&expand=voucher&is_available=false'
|
||||
.format(organizer.slug, event.slug))
|
||||
@@ -1769,7 +1769,7 @@ def test_event_expand_seat_filter_and_querycount(token_client, organizer, event,
|
||||
v1 = event.vouchers.create(item=item, seat=event.seats.get(seat_guid='0-1'))
|
||||
v2 = event.vouchers.create(item=item, seat=event.seats.get(seat_guid='0-2'))
|
||||
|
||||
with assert_num_queries(13):
|
||||
with assert_num_queries(16):
|
||||
resp = token_client.get('/api/v1/organizers/{}/events/{}/seats/'
|
||||
'?expand=orderposition&expand=cartposition&expand=voucher&is_available=false'
|
||||
.format(organizer.slug, event.slug))
|
||||
|
||||
@@ -81,6 +81,8 @@ TEST_VOUCHER_RES = {
|
||||
'all_bundles_included': False,
|
||||
'subevent': None,
|
||||
'seat': None,
|
||||
'budget': None,
|
||||
'budget_used': "0.00",
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user