mirror of
https://github.com/pretix/pretix.git
synced 2026-05-10 16:04:02 +00:00
Ask only for VAT ID if company is inside EU (#1709)
Co-authored-by: Andreas Teuber <andreas.teuber@passiv.de> Co-authored-by: Raphael Michel <mail@raphaelmichel.de>
This commit is contained in:
@@ -580,7 +580,7 @@ class BaseInvoiceAddressForm(forms.ModelForm):
|
|||||||
'data-display-dependency': '#id_is_business_1',
|
'data-display-dependency': '#id_is_business_1',
|
||||||
'autocomplete': 'organization',
|
'autocomplete': 'organization',
|
||||||
}),
|
}),
|
||||||
'vat_id': forms.TextInput(attrs={'data-display-dependency': '#id_is_business_1'}),
|
'vat_id': forms.TextInput(attrs={'data-display-dependency': '#id_is_business_1', 'data-countries-in-eu': ','.join(EU_COUNTRIES)}),
|
||||||
'internal_reference': forms.TextInput,
|
'internal_reference': forms.TextInput,
|
||||||
}
|
}
|
||||||
labels = {
|
labels = {
|
||||||
@@ -630,6 +630,11 @@ class BaseInvoiceAddressForm(forms.ModelForm):
|
|||||||
)
|
)
|
||||||
self.fields['state'].widget.is_required = True
|
self.fields['state'].widget.is_required = True
|
||||||
|
|
||||||
|
# Without JavaScript the VAT ID field is not hidden, so we empty the field if a country outside the EU is selected.
|
||||||
|
if cc and cc not in EU_COUNTRIES and fprefix + 'vat_id' in self.data:
|
||||||
|
self.data = self.data.copy()
|
||||||
|
del self.data[fprefix + 'vat_id']
|
||||||
|
|
||||||
if not event.settings.invoice_address_required or self.all_optional:
|
if not event.settings.invoice_address_required or self.all_optional:
|
||||||
for k, f in self.fields.items():
|
for k, f in self.fields.items():
|
||||||
f.required = False
|
f.required = False
|
||||||
@@ -644,8 +649,6 @@ class BaseInvoiceAddressForm(forms.ModelForm):
|
|||||||
self.fields['company'].widget.is_required = True
|
self.fields['company'].widget.is_required = True
|
||||||
self.fields['company'].widget.attrs['required'] = 'required'
|
self.fields['company'].widget.attrs['required'] = 'required'
|
||||||
del self.fields['company'].widget.attrs['data-display-dependency']
|
del self.fields['company'].widget.attrs['data-display-dependency']
|
||||||
if 'vat_id' in self.fields:
|
|
||||||
del self.fields['vat_id'].widget.attrs['data-display-dependency']
|
|
||||||
|
|
||||||
self.fields['name_parts'] = NamePartsFormField(
|
self.fields['name_parts'] = NamePartsFormField(
|
||||||
max_length=255,
|
max_length=255,
|
||||||
@@ -677,6 +680,9 @@ class BaseInvoiceAddressForm(forms.ModelForm):
|
|||||||
data = self.cleaned_data
|
data = self.cleaned_data
|
||||||
if not data.get('is_business'):
|
if not data.get('is_business'):
|
||||||
data['company'] = ''
|
data['company'] = ''
|
||||||
|
data['vat_id'] = ''
|
||||||
|
if data.get('is_business') and not data.get('country') in EU_COUNTRIES:
|
||||||
|
data['vat_id'] = ''
|
||||||
if self.event.settings.invoice_address_required:
|
if self.event.settings.invoice_address_required:
|
||||||
if data.get('is_business') and not data.get('company'):
|
if data.get('is_business') and not data.get('company'):
|
||||||
raise ValidationError(_('You need to provide a company name.'))
|
raise ValidationError(_('You need to provide a company name.'))
|
||||||
@@ -697,7 +703,6 @@ class BaseInvoiceAddressForm(forms.ModelForm):
|
|||||||
) and len(data.get('name_parts', {})) == 1:
|
) and len(data.get('name_parts', {})) == 1:
|
||||||
# Do not save the country if it is the only field set -- we don't know the user even checked it!
|
# Do not save the country if it is the only field set -- we don't know the user even checked it!
|
||||||
self.cleaned_data['country'] = ''
|
self.cleaned_data['country'] = ''
|
||||||
|
|
||||||
if self.validate_vat_id and self.instance.vat_id_validated and 'vat_id' not in self.changed_data:
|
if self.validate_vat_id and self.instance.vat_id_validated and 'vat_id' not in self.changed_data:
|
||||||
pass
|
pass
|
||||||
elif self.validate_vat_id and data.get('is_business') and data.get('country') in EU_COUNTRIES and data.get('vat_id'):
|
elif self.validate_vat_id and data.get('is_business') and data.get('country') in EU_COUNTRIES and data.get('vat_id'):
|
||||||
|
|||||||
@@ -314,6 +314,24 @@ var form_handlers = function (el) {
|
|||||||
dependency.closest('.form-group').find('input[name=' + dependency.attr("name") + ']').on("dp.change", update);
|
dependency.closest('.form-group').find('input[name=' + dependency.attr("name") + ']').on("dp.change", update);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("input[name$=vat_id][data-countries-in-eu]").each(function () {
|
||||||
|
var dependent = $(this),
|
||||||
|
dependency_country = $(this).closest(".panel-body, form").find('select[name$=country]'),
|
||||||
|
dependency_id_is_business_1 = $(this).closest(".panel-body, form").find('input[id$=id_is_business_1]'),
|
||||||
|
update = function (ev) {
|
||||||
|
if (dependency_id_is_business_1.length && !dependency_id_is_business_1.prop("checked")) {
|
||||||
|
dependent.closest(".form-group").hide();
|
||||||
|
} else if (dependent.attr('data-countries-in-eu').split(',').includes(dependency_country.val())) {
|
||||||
|
dependent.closest(".form-group").show();
|
||||||
|
} else {
|
||||||
|
dependent.closest(".form-group").hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
update();
|
||||||
|
dependency_country.on("change", update);
|
||||||
|
dependency_id_is_business_1.on("change", update);
|
||||||
|
});
|
||||||
|
|
||||||
$("select[name$=state]:not([data-static])").each(function () {
|
$("select[name$=state]:not([data-static])").each(function () {
|
||||||
var dependent = $(this),
|
var dependent = $(this),
|
||||||
counter = 0,
|
counter = 0,
|
||||||
|
|||||||
@@ -293,6 +293,24 @@ $(function () {
|
|||||||
dependency.closest('.form-group, form').find('input[name=' + dependency.attr("name") + ']').on("dp.change", update);
|
dependency.closest('.form-group, form').find('input[name=' + dependency.attr("name") + ']').on("dp.change", update);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("input[name$=vat_id][data-countries-in-eu]").each(function () {
|
||||||
|
var dependent = $(this),
|
||||||
|
dependency_country = $(this).closest(".panel-body, form").find('select[name$=country]'),
|
||||||
|
dependency_id_is_business_1 = $(this).closest(".panel-body, form").find('input[id$=id_is_business_1]'),
|
||||||
|
update = function (ev) {
|
||||||
|
if (dependency_id_is_business_1.length && !dependency_id_is_business_1.prop("checked")) {
|
||||||
|
dependent.closest(".form-group").hide();
|
||||||
|
} else if (dependent.attr('data-countries-in-eu').split(',').includes(dependency_country.val())) {
|
||||||
|
dependent.closest(".form-group").show();
|
||||||
|
} else {
|
||||||
|
dependent.closest(".form-group").hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
update();
|
||||||
|
dependency_country.on("change", update);
|
||||||
|
dependency_id_is_business_1.on("change", update);
|
||||||
|
});
|
||||||
|
|
||||||
$("select[name$=state]").each(function () {
|
$("select[name$=state]").each(function () {
|
||||||
var dependent = $(this),
|
var dependent = $(this),
|
||||||
counter = 0,
|
counter = 0,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ base_patterns = [
|
|||||||
url(r'^metrics$', metrics.serve_metrics,
|
url(r'^metrics$', metrics.serve_metrics,
|
||||||
name='metrics'),
|
name='metrics'),
|
||||||
url(r'^csp_report/$', csp.csp_report, name='csp.report'),
|
url(r'^csp_report/$', csp.csp_report, name='csp.report'),
|
||||||
url(r'^js_helpers/states/$', js_helpers.states, name='js_helpers.stats'),
|
url(r'^js_helpers/states/$', js_helpers.states, name='js_helpers.states'),
|
||||||
url(r'^api/v1/', include(('pretix.api.urls', 'pretixapi'), namespace='api-v1')),
|
url(r'^api/v1/', include(('pretix.api.urls', 'pretixapi'), namespace='api-v1')),
|
||||||
url(r'^api/$', RedirectView.as_view(url='/api/v1/'), name='redirect-api-version')
|
url(r'^api/$', RedirectView.as_view(url='/api/v1/'), name='redirect-api-version')
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user