Tax rules: Allow to block countries from making a purchase

This commit is contained in:
Raphael Michel
2020-11-22 13:27:58 +01:00
parent 168a6bae98
commit 6d9e1be844
8 changed files with 145 additions and 47 deletions

View File

@@ -23,7 +23,7 @@ from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic import TemplateView, View
from pretix.base.models import (
CachedTicket, GiftCard, Invoice, Order, OrderPosition, Quota,
CachedTicket, GiftCard, Invoice, Order, OrderPosition, Quota, TaxRule,
)
from pretix.base.models.orders import (
CachedCombinedTicket, InvoiceAddress, OrderFee, OrderPayment, OrderRefund,
@@ -699,6 +699,13 @@ class OrderModify(EventViewMixin, OrderDetailMixin, OrderQuestionsViewMixin, Tem
messages.error(self.request,
_("We had difficulties processing your input. Please review the errors below."))
return self.get(request, *args, **kwargs)
if 'country' in self.invoice_form.cleaned_data:
trs = TaxRule.objects.filter(id__in=[p.tax_rule_id for p in self.positions])
for tr in trs:
if tr.get_matching_rule(self.invoice_form.instance).get('action', 'vat') == 'block':
messages.error(self.request,
_('One of the selected products is not available in the selected country.'))
return self.get(request, *args, **kwargs)
if hasattr(self.invoice_form, 'save'):
self.invoice_form.save()
self.order.log_action('pretix.event.order.modified', {