mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 00:52:03 +01:00 
			
		
		
		
	Restructure payment model
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		@@ -364,27 +364,28 @@ class StudentRegistration(ParticipantRegistration):
 | 
			
		||||
                })
 | 
			
		||||
 | 
			
		||||
        if self.team and self.team.participation.valid:
 | 
			
		||||
            if self.payment.valid is False:
 | 
			
		||||
                text = _("You have to pay {amount} € for your registration, or send a scholarship "
 | 
			
		||||
                         "notification or a payment proof. "
 | 
			
		||||
                         "You can do it on <a href=\"{url}\">the payment page</a>.")
 | 
			
		||||
                url = reverse_lazy("registration:update_payment", args=(self.payment.id,))
 | 
			
		||||
                content = format_lazy(text, amount=self.team.participation.tournament.price, url=url)
 | 
			
		||||
                informations.append({
 | 
			
		||||
                    'title': _("Payment"),
 | 
			
		||||
                    'type': "danger",
 | 
			
		||||
                    'priority': 3,
 | 
			
		||||
                    'content': content,
 | 
			
		||||
                })
 | 
			
		||||
            elif self.payment.valid is None:
 | 
			
		||||
                text = _("Your payment is under approval.")
 | 
			
		||||
                content = text
 | 
			
		||||
                informations.append({
 | 
			
		||||
                    'title': _("Payment"),
 | 
			
		||||
                    'type': "warning",
 | 
			
		||||
                    'priority': 3,
 | 
			
		||||
                    'content': content,
 | 
			
		||||
                })
 | 
			
		||||
            for payment in self.payments.all():
 | 
			
		||||
                if payment.valid is False:
 | 
			
		||||
                    text = _("You have to pay {amount} € for your registration, or send a scholarship "
 | 
			
		||||
                             "notification or a payment proof. "
 | 
			
		||||
                             "You can do it on <a href=\"{url}\">the payment page</a>.")
 | 
			
		||||
                    url = reverse_lazy("registration:update_payment", args=(payment.id,))
 | 
			
		||||
                    content = format_lazy(text, amount=payment.amount, url=url)
 | 
			
		||||
                    informations.append({
 | 
			
		||||
                        'title': _("Payment"),
 | 
			
		||||
                        'type': "danger",
 | 
			
		||||
                        'priority': 3,
 | 
			
		||||
                        'content': content,
 | 
			
		||||
                    })
 | 
			
		||||
                elif self.payment.valid is None:
 | 
			
		||||
                    text = _("Your payment is under approval.")
 | 
			
		||||
                    content = text
 | 
			
		||||
                    informations.append({
 | 
			
		||||
                        'title': _("Payment"),
 | 
			
		||||
                        'type': "warning",
 | 
			
		||||
                        'priority': 3,
 | 
			
		||||
                        'content': content,
 | 
			
		||||
                    })
 | 
			
		||||
 | 
			
		||||
        return informations
 | 
			
		||||
 | 
			
		||||
@@ -496,11 +497,28 @@ def get_scholarship_filename(instance, filename):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Payment(models.Model):
 | 
			
		||||
    registration = models.OneToOneField(
 | 
			
		||||
    registrations = models.ManyToManyField(
 | 
			
		||||
        ParticipantRegistration,
 | 
			
		||||
        on_delete=models.CASCADE,
 | 
			
		||||
        related_name="payment",
 | 
			
		||||
        verbose_name=_("registration"),
 | 
			
		||||
        related_name="payments",
 | 
			
		||||
        verbose_name=_("registrations"),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    grouped = models.BooleanField(
 | 
			
		||||
        verbose_name=_("grouped"),
 | 
			
		||||
        default=False,
 | 
			
		||||
        help_text=_("If set to true, then one payment is made for the full team, "
 | 
			
		||||
                    "for example if the school pays for all."),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    amount = models.PositiveSmallIntegerField(
 | 
			
		||||
        verbose_name=_("total amount"),
 | 
			
		||||
        help_text=_("Corresponds to the total required amount to pay, in euros."),
 | 
			
		||||
        default=0,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    final = models.BooleanField(
 | 
			
		||||
        verbose_name=_("for final tournament"),
 | 
			
		||||
        default=False,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    type = models.CharField(
 | 
			
		||||
@@ -518,9 +536,16 @@ class Payment(models.Model):
 | 
			
		||||
        default="",
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    scholarship_file = models.FileField(
 | 
			
		||||
        verbose_name=_("scholarship file"),
 | 
			
		||||
        help_text=_("only if you have a scholarship."),
 | 
			
		||||
    checkout_intent_id = models.IntegerField(
 | 
			
		||||
        verbose_name=_("Hello Asso checkout intent ID"),
 | 
			
		||||
        blank=True,
 | 
			
		||||
        null=True,
 | 
			
		||||
        default=None,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    receipt = models.FileField(
 | 
			
		||||
        verbose_name=_("receipt"),
 | 
			
		||||
        help_text=_("only if you have a scholarship or if you chose a bank transfer."),
 | 
			
		||||
        upload_to=get_scholarship_filename,
 | 
			
		||||
        blank=True,
 | 
			
		||||
        default="",
 | 
			
		||||
@@ -540,10 +565,10 @@ class Payment(models.Model):
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def get_absolute_url(self):
 | 
			
		||||
        return reverse_lazy("registration:user_detail", args=(self.registration.user.id,))
 | 
			
		||||
        return reverse_lazy("registration:update_payment", args=(self.pk,))
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return _("Payment of {registration}").format(registration=self.registration)
 | 
			
		||||
        return _("Payment of {registrations}").format(registrations=", ".join(map(str, self.registrations.all())))
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        verbose_name = _("payment")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user