Checkout: improve heuristic to open invoice-panel (#3545)

This commit is contained in:
Richard Schreiber
2023-08-24 16:15:47 +02:00
committed by GitHub
parent 38173e3a54
commit 21864885cb
3 changed files with 21 additions and 2 deletions

View File

@@ -1026,6 +1026,25 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
ctx['cart_session'] = self.cart_session
ctx['invoice_address_asked'] = self.address_asked
def reduce_initial(v):
if isinstance(v, dict):
# try to flatten objects such as name_parts to a single string to determine whether they have any value set
return ''.join([v for k, v in v.items() if not k.startswith('_')])
else:
return v
def is_form_filled(form, ignore_keys=()):
return any([reduce_initial(v) for k, v in form.initial.items() if k not in ignore_keys])
ctx['invoice_address_open'] = (
self.request.event.settings.invoice_address_required or
self.request.event.settings.invoice_name_required or
'invoice' in self.request.GET or
# Checking for self.invoice_address.pk is not enough as when an invoice_address has been added and later edited to be empty, its not None.
# So check initial values as invoice_form can receive pre-filled values from invoice_address, widget-data or overwrites from plug-ins.
is_form_filled(self.invoice_form, ignore_keys=('is_business', 'country'))
)
if self.cart_customer:
if self.address_asked:
addresses = self.cart_customer.stored_addresses.all()

View File

@@ -76,7 +76,7 @@
<div class="panel-heading">
<h3 class="panel-title">
{% trans "Invoice information" %}
<a href="{% eventurl request.event "presale:event.checkout" step="questions" cart_namespace=cart_namespace|default_if_none:"" %}?invoice=1" aria-label="{% trans "Modify invoice information" %}" class="h6">
<a href="{% eventurl request.event "presale:event.checkout" step="questions" cart_namespace=cart_namespace|default_if_none:"" %}?invoice=1#invoice-details" aria-label="{% trans "Modify invoice information" %}" class="h6">
<span class="fa fa-edit" aria-hidden="true"></span>{% trans "Modify" %}
</a>
</h3>

View File

@@ -34,7 +34,7 @@
</div>
</details>
{% if invoice_address_asked %}
<details class="panel panel-default" {% if event.settings.invoice_address_required or event.settings.invoice_name_required %}open{% endif %}>
<details class="panel panel-default" {% if invoice_address_open %}open{% endif %} id="invoice-details">
<summary class="panel-heading">
<h3 class="panel-title">
<strong>{% trans "Invoice information" %}{% if not event.settings.invoice_address_required and not event.settings.invoice_name_required %}