Use correct info to decide when to show VAT fields
authorMagnus Hagander <magnus@hagander.net>
Wed, 22 Jan 2025 20:46:21 +0000 (21:46 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 22 Jan 2025 20:46:21 +0000 (21:46 +0100)
The VAT refund fields on anything should be driven off whether there's
actual VAT on the invoice, not off the EU_VAT setting. In particular,
when using taxes and not being in the EU, EU_VAT should be turned off,
but we must still be able to refund the VAT...

Diagnosed by Steve Singer

postgresqleu/confreg/backendforms.py
postgresqleu/confreg/backendviews.py
postgresqleu/confsponsor/forms.py
postgresqleu/confsponsor/views.py

index 56cbbcaf62062002d547b5cbfdbf31bfb335008f..69d6caa0973232b5ca93f1009de7f6ada0f3bf38 100644 (file)
@@ -1902,7 +1902,7 @@ class BulkPaymentRefundForm(django.forms.Form):
         else:
             self.fields['amount'].help_text = 'Invoice total value is {}{}'.format(settings.CURRENCY_SYMBOL, invoice.total_amount - invoice.total_vat)
 
-        if not settings.EU_VAT:
+        if not invoice.total_vat:
             del self.fields['vatamount']
         else:
             self.fields['vatamount'].validators = [MinValueValidator(0), MaxValueValidator(total['remaining']['vatamount'])]
index 21766f51b35e6b1c9c7e498674797fe972272e9c..bff20e6d60e3e64dff9cfaafe9a73914b7a4d0b2 100644 (file)
@@ -697,7 +697,7 @@ def prepaidorder_refund(request, urlname, orderid):
     else:
         form = PurchasedVoucherRefundForm()
 
-    if settings.EU_VAT:
+    if invoice.total_vat > 0:
         note = 'You are about to refund {}{} ({}{} + {}{} VAT) for invoice {}. Please confirm that this is what you want!'.format(settings.CURRENCY_SYMBOL, invoice.total_amount, settings.CURRENCY_SYMBOL, invoice.total_amount - invoice.total_vat, settings.CURRENCY_SYMBOL, invoice.total_vat, invoice.id)
     else:
         note = 'You are about to refund {}{} for invoice {}. Please confirm that this is what you want!'.format(settings.CURRENCY_SYMBOL, invoice.total_amount, invoice.id)
index ab646cbc377630ec22274972311e1f2d81acf723..0656e8bfa3b92acec7f94db87268df199f2f6005 100644 (file)
@@ -251,9 +251,10 @@ class SponsorRefundForm(forms.Form):
     ), label="Cancel method")
     confirm = forms.BooleanField(help_text="Confirm that you want to cancel or refund this sponsorship!")
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, invoice, *args, **kwargs):
+        self.invoice = invoice
         super().__init__(*args, **kwargs)
-        if not settings.EU_VAT:
+        if not invoice.total_vat:
             self.fields['customrefundamount'].label = 'Custom refund amount'
             del self.fields['customrefundamountvat']
 
@@ -268,12 +269,12 @@ class SponsorRefundForm(forms.Form):
                 self.add_error('customrefundamount', 'This field is required when doing custom amount refund')
             elif Decimal(d['customrefundamount'] <= 0):
                 self.add_error('customrefundamount', 'Must be >0 when performing custom refund')
-            if settings.EU_VAT and d['customrefundamountvat'] is None:
+            if self.invoice.total_vat and d['customrefundamountvat'] is None:
                 self.add_error('customrefundamountvat', 'This field is required when doing custom amount refund')
         else:
             if d['customrefundamount'] is not None:
                 self.add_error('customrefundamount', 'This field must be left empty when doing non-custom refund')
-            if settings.EU_VAT and d['customrefundamountvat'] is not None:
+            if self.invoice.total_vat and d['customrefundamountvat'] is not None:
                 self.add_error('customrefundamountvat', 'This field must be left empty when doing non-custom refund')
 
         return d
index c19cfa6bd997123aba228f316bda794a7d96bbf9..48fc2fe8f7c65e0af52bc9af0926cea9978a9f0d 100644 (file)
@@ -1529,7 +1529,7 @@ def sponsor_admin_refund(request, confurlname, sponsorid):
             return HttpResponseRedirect("../")
 
     if request.method == 'POST':
-        form = SponsorRefundForm(data=request.POST)
+        form = SponsorRefundForm(invoice, data=request.POST)
         if form.is_valid():
             class _AbortValidation(Exception):
                 pass
@@ -1555,7 +1555,7 @@ def sponsor_admin_refund(request, confurlname, sponsorid):
                     # Custom amount
                     if form.cleaned_data['customrefundamount'] > total_refunds['remaining']['amount']:
                         form.add_error('customrefundamount', "Only {} {} non-vat remains to be refunded on this invoice".format(settings.CURRENCY_SYMBOL, total_refunds['remaining']['amount']))
-                    if settings.EU_VAT and form.cleaned_data['customrefundamountvat'] > total_refunds['remaining']['vatamount']:
+                    if invoice.total_vat and form.cleaned_data['customrefundamountvat'] > total_refunds['remaining']['vatamount']:
                         form.add_error('customrefundamountvat', "Only {} {} VAT remains to be refunded on this invoice".format(settings.CURRENCY_SYMBOL, total_refunds['remaining']['vatamount']))
                 elif form.cleaned_data['refundamount'] == "2":
                     # No refund, just cancel
@@ -1644,7 +1644,7 @@ def sponsor_admin_refund(request, confurlname, sponsorid):
                     elif form.cleaned_data['refundamount'] == "1":
                         # Refund the specific amount
                         to_refund = form.cleaned_data['customrefundamount']
-                        if settings.EU_VAT:
+                        if invoice.total_vat:
                             to_refund_vat = form.cleaned_data['customrefundamountvat']
                         else:
                             to_refund_vat = 0
@@ -1683,7 +1683,7 @@ def sponsor_admin_refund(request, confurlname, sponsorid):
                 # Fall through and re-render form
                 pass
     else:
-        form = SponsorRefundForm()
+        form = SponsorRefundForm(invoice)
 
     return render(request, 'confsponsor/admin_sponsor_refund.html', {
         'conference': conference,