Grouping payments is only allowed if all members of a team have not paid yet

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-02-24 08:54:01 +01:00
parent 87038dd6f4
commit 295717256f
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 32 additions and 20 deletions

View File

@ -24,25 +24,27 @@
</p>
<p>
{% if payment.grouped %}
{% blocktrans trimmed %}
You want finally that each member pays its own registration? Then click on the button:
{% endblocktrans %}
<div class="text-center">
<a href="{% url 'registration:update_payment_group_mode' pk=payment.pk %}" class="btn btn-warning">
<i class="fas fa-user"></i> {% trans "Back to single payments" %}
</a>
</div>
{% else %}
{% blocktrans trimmed %}
You want to pay for the registrations of all members of your team,
or your school will pay for all registrations? Then click on the button:
{% endblocktrans %}
<div class="text-center">
<a href="{% url 'registration:update_payment_group_mode' pk=payment.pk %}" class="btn btn-warning">
<i class="fas fa-users"></i> {% trans "Group the payments of my team" %}
</a>
</div>
{% if can_group %}
{% if payment.grouped %}
{% blocktrans trimmed %}
You want finally that each member pays its own registration? Then click on the button:
{% endblocktrans %}
<div class="text-center">
<a href="{% url 'registration:update_payment_group_mode' pk=payment.pk %}" class="btn btn-warning">
<i class="fas fa-user"></i> {% trans "Back to single payments" %}
</a>
</div>
{% else %}
{% blocktrans trimmed %}
You want to pay for the registrations of all members of your team,
or your school will pay for all registrations? Then click on the button:
{% endblocktrans %}
<div class="text-center">
<a href="{% url 'registration:update_payment_group_mode' pk=payment.pk %}" class="btn btn-warning">
<i class="fas fa-users"></i> {% trans "Group the payments of my team" %}
</a>
</div>
{% endif %}
{% endif %}
</p>

View File

@ -459,6 +459,9 @@ class PaymentUpdateView(LoginRequiredMixin, UpdateView):
def get_context_data(self, **kwargs):
context = super().get_context_data()
context['title'] = _("Update payment")
# Grouping is only possible if there isn't any validated payment in the team
context['can_group'] = all(p.valid is False for reg in self.object.team.students.all()
for p in reg.payments.filter(valid=self.object.valid).all())
context['bank_transfer_form'] = PaymentForm(payment_type='bank_transfer',
data=self.request.POST or None,
instance=self.object)
@ -489,11 +492,18 @@ class PaymentUpdateGroupView(LoginRequiredMixin, DetailView):
model = Payment
def dispatch(self, request, *args, **kwargs):
payment = self.get_object()
if not self.request.user.is_authenticated or \
not self.request.user.registration.is_admin \
and (self.request.user.registration not in self.get_object().registrations.all()
or self.get_object().valid is not False):
or payment.valid is not False):
return self.handle_no_permission()
if any(p.valid is not False for reg in payment.team.students.all()
for p in reg.payments.filter(valid=payment.valid).all()):
raise PermissionDenied(_("Since one payment is already validated, or pending validation, "
"grouping is not possible."))
return super().dispatch(request, *args, **kwargs)
def get(self, request, *args, **kwargs):