forked from CGM_Public/pretix_original
Checkout: Delete invoice address if no longer required (Z#23203488) (#5358)
This commit is contained in:
@@ -3314,6 +3314,24 @@ class InvoiceAddress(models.Model):
|
||||
kwargs['update_fields'] = {'name_cached', 'name_parts'}.union(kwargs['update_fields'])
|
||||
super().save(**kwargs)
|
||||
|
||||
def clear(self, except_name=False):
|
||||
self.is_business = False
|
||||
if not except_name:
|
||||
self.name_cached = ""
|
||||
self.name_parts = {}
|
||||
self.company = ""
|
||||
self.street = ""
|
||||
self.zipcode = ""
|
||||
self.city = ""
|
||||
self.country_old = ""
|
||||
self.country = ""
|
||||
self.state = ""
|
||||
self.vat_id = ""
|
||||
self.vat_id_validated = False
|
||||
self.custom_field = None
|
||||
self.internal_reference = ""
|
||||
self.beneficiary = ""
|
||||
|
||||
def describe(self):
|
||||
parts = [
|
||||
self.company,
|
||||
|
||||
@@ -959,6 +959,10 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
d['phone'] = str(d['phone'])
|
||||
self.cart_session['contact_form_data'] = d
|
||||
if self.address_asked or self.request.event.settings.invoice_name_required:
|
||||
if not self.address_asked:
|
||||
# Invoice address was there, but is no longer asked for, however, name is still required
|
||||
self.invoice_form.instance.clear(except_name=True)
|
||||
|
||||
addr = self.invoice_form.save()
|
||||
|
||||
if self.cart_customer and self.invoice_form.cleaned_data.get('save'):
|
||||
@@ -997,6 +1001,10 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
'rate to your purchase and the price of the products in your cart has '
|
||||
'changed accordingly.'))
|
||||
return redirect_to_url(self.get_next_url(request) + '?open_cart=true')
|
||||
elif 'invoice_address' in self.cart_session:
|
||||
# Invoice address was there, but is no longer asked for
|
||||
self.invoice_address.delete()
|
||||
del self.cart_session['invoice_address']
|
||||
|
||||
try:
|
||||
validate_memberships_in_order(self.cart_customer, self.positions, self.request.event, lock=False,
|
||||
|
||||
Reference in New Issue
Block a user