mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 06:22:13 +01:00 
			
		
		
		
	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:
		@@ -24,6 +24,7 @@
 | 
			
		||||
            </p>
 | 
			
		||||
 | 
			
		||||
            <p>
 | 
			
		||||
                {% if can_group %}
 | 
			
		||||
                    {% if payment.grouped %}
 | 
			
		||||
                        {% blocktrans trimmed %}
 | 
			
		||||
                            You want finally that each member pays its own registration? Then click on the button:
 | 
			
		||||
@@ -44,6 +45,7 @@
 | 
			
		||||
                            </a>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </p>
 | 
			
		||||
 | 
			
		||||
            <ul>
 | 
			
		||||
 
 | 
			
		||||
@@ -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):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user