mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Bank transfer: Enable organizer-level features with multiple currencies (#3177)
Co-authored-by: Martin Gross <gross@rami.io>
This commit is contained in:
@@ -26,7 +26,7 @@ from django.db.models import Q
|
||||
from django.utils.timezone import now
|
||||
from django_filters.rest_framework import DjangoFilterBackend, FilterSet
|
||||
from rest_framework import serializers, status, viewsets
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework.exceptions import PermissionDenied, ValidationError
|
||||
from rest_framework.mixins import CreateModelMixin
|
||||
from rest_framework.response import Response
|
||||
|
||||
@@ -46,7 +46,7 @@ class BankTransactionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = BankTransaction
|
||||
fields = ('state', 'message', 'checksum', 'payer', 'reference', 'amount', 'date', 'order',
|
||||
'comment', 'iban', 'bic')
|
||||
'comment', 'iban', 'bic', 'currency')
|
||||
|
||||
|
||||
class BankImportJobSerializer(serializers.ModelSerializer):
|
||||
@@ -57,7 +57,7 @@ class BankImportJobSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = BankImportJob
|
||||
fields = ('id', 'event', 'created', 'state', 'transactions')
|
||||
fields = ('id', 'event', 'created', 'state', 'transactions', 'currency')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.organizer = kwargs.pop('organizer')
|
||||
@@ -65,6 +65,18 @@ class BankImportJobSerializer(serializers.ModelSerializer):
|
||||
self.fields['event'].queryset = self.organizer.events.all()
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def validate(self, attrs):
|
||||
if not attrs.get("event"):
|
||||
if "currency" not in attrs:
|
||||
currencies = list(
|
||||
self.organizer.events.order_by('currency').values_list('currency', flat=True).distinct()
|
||||
)
|
||||
if len(currencies) != 1:
|
||||
raise ValidationError({"currency": ["Currency is ambiguous, please set explicitly."]})
|
||||
else:
|
||||
attrs["currency"] = currencies[0]
|
||||
return attrs
|
||||
|
||||
def create(self, validated_data):
|
||||
trans_data = validated_data.pop('transactions')
|
||||
job = BankImportJob.objects.create(organizer=self.organizer, **validated_data)
|
||||
|
||||
Reference in New Issue
Block a user