mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Mise en place des paiements en plusieurs fois (partie BACK) [#25]
This commit is contained in:
58
Back-End/School/management/commands/init_payment_plans.py
Normal file
58
Back-End/School/management/commands/init_payment_plans.py
Normal file
@ -0,0 +1,58 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from School.models import PaymentPlan, PaymentPlanType, FeeType
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Initialize or update Payment Plans'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
self.create_or_update_payment_plans()
|
||||
|
||||
def create_or_update_payment_plans(self):
|
||||
current_date = timezone.now().date()
|
||||
|
||||
for fee_type in FeeType.choices:
|
||||
fee_type_value = fee_type[0]
|
||||
|
||||
# 1 fois - échéance à 1 mois à partir de la date actuelle
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=PaymentPlanType.ONE_TIME,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'due_dates': [current_date + relativedelta(months=1)],
|
||||
'is_active': True
|
||||
}
|
||||
)
|
||||
|
||||
# 3 fois - échéances espacées de 4 mois
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=PaymentPlanType.THREE_TIMES,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'due_dates': [current_date + relativedelta(months=1+4*i) for i in range(3)],
|
||||
'is_active': False
|
||||
}
|
||||
)
|
||||
|
||||
# 10 fois - échéances espacées d'un mois
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=PaymentPlanType.TEN_TIMES,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'due_dates': [current_date + relativedelta(months=1+i) for i in range(10)],
|
||||
'is_active': False
|
||||
}
|
||||
)
|
||||
|
||||
# 12 fois - échéances espacées d'un mois
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=PaymentPlanType.TWELVE_TIMES,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'due_dates': [current_date + relativedelta(months=1+i) for i in range(12)],
|
||||
'is_active': False
|
||||
}
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Payment Plans initialized or updated successfully'))
|
||||
@ -108,4 +108,8 @@ class PaymentPlan(models.Model):
|
||||
frequency = models.IntegerField(choices=PaymentPlanType.choices, default=PaymentPlanType.ONE_TIME)
|
||||
due_dates = ArrayField(models.DateField(), blank=True)
|
||||
type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE)
|
||||
is_active = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.get_frequency_display()} - {self.get_type_display()}"
|
||||
|
||||
|
||||
@ -221,7 +221,7 @@ class RegistrationFileTemplate(models.Model):
|
||||
order = models.PositiveIntegerField(default=0) # Ajout du champ order
|
||||
date_added = models.DateTimeField(auto_now_add=True)
|
||||
is_required = models.BooleanField(default=False)
|
||||
group = models.ForeignKey(RegistrationFileGroup, on_delete=models.CASCADE, related_name='file_templates')
|
||||
group = models.ForeignKey(RegistrationFileGroup, on_delete=models.CASCADE, related_name='file_templates', null=True, blank=True)
|
||||
|
||||
@property
|
||||
def formatted_date_added(self):
|
||||
|
||||
@ -18,7 +18,8 @@ commands = [
|
||||
["python", "manage.py", "makemigrations", "GestionMessagerie", "--noinput"],
|
||||
["python", "manage.py", "makemigrations", "Auth", "--noinput"],
|
||||
["python", "manage.py", "makemigrations", "School", "--noinput"],
|
||||
["python", "manage.py", "migrate", "--noinput"]
|
||||
["python", "manage.py", "migrate", "--noinput"],
|
||||
["python", "manage.py", "init_payment_plans"]
|
||||
]
|
||||
|
||||
for command in commands:
|
||||
|
||||
Reference in New Issue
Block a user