mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Ajout de la configuration des tarifs de l'école [#18]
This commit is contained in:
committed by
Luc SORIGNET
parent
147a70135d
commit
5a0e65bb75
@ -3,6 +3,9 @@ from Auth.models import Profile
|
||||
from django.db.models import JSONField
|
||||
from django.dispatch import receiver
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
LEVEL_CHOICES = [
|
||||
(1, 'Très Petite Section (TPS)'),
|
||||
@ -47,7 +50,7 @@ class SchoolClass(models.Model):
|
||||
number_of_students = models.PositiveIntegerField(blank=True)
|
||||
teaching_language = models.CharField(max_length=255, blank=True)
|
||||
school_year = models.CharField(max_length=9, blank=True)
|
||||
updated_date = models.DateTimeField(auto_now_add=True)
|
||||
updated_date = models.DateTimeField(auto_now=True)
|
||||
teachers = models.ManyToManyField(Teacher, blank=True)
|
||||
levels = ArrayField(models.IntegerField(choices=LEVEL_CHOICES), default=list)
|
||||
type = models.IntegerField(choices=PLANNING_TYPE_CHOICES, default=1)
|
||||
@ -64,3 +67,56 @@ class Planning(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return f'Planning for {self.level} of {self.school_class.atmosphere_name}'
|
||||
|
||||
class Discount(models.Model):
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
amount = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
description = models.TextField(blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Fee(models.Model):
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
amount = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
description = models.TextField(blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class TuitionFee(models.Model):
|
||||
class PaymentOptions(models.IntegerChoices):
|
||||
SINGLE_PAYMENT = 0, _('Paiement en une seule fois')
|
||||
FOUR_TIME_PAYMENT = 1, _('Paiement en 4 fois')
|
||||
TEN_TIME_PAYMENT = 2, _('Paiement en 10 fois')
|
||||
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
description = models.TextField(blank=True)
|
||||
base_amount = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
currency = models.CharField(max_length=3, default='EUR')
|
||||
discounts = models.ManyToManyField('Discount', blank=True)
|
||||
validity_start_date = models.DateField()
|
||||
validity_end_date = models.DateField()
|
||||
payment_option = models.IntegerField(choices=PaymentOptions, default=PaymentOptions.SINGLE_PAYMENT)
|
||||
is_active = models.BooleanField(default=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def clean(self):
|
||||
if self.validity_end_date <= self.validity_start_date:
|
||||
raise ValidationError(_('La date de fin de validité doit être après la date de début de validité.'))
|
||||
|
||||
def calculate_final_amount(self):
|
||||
amount = self.base_amount
|
||||
|
||||
# Apply fees (supplements and taxes)
|
||||
# for fee in self.fees.all():
|
||||
# amount += fee.amount
|
||||
|
||||
# Apply discounts
|
||||
for discount in self.discounts.all():
|
||||
amount -= discount.amount
|
||||
|
||||
return amount
|
||||
|
||||
Reference in New Issue
Block a user