from django.db import models 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)'), (2, 'Petite Section (PS)'), (3, 'Moyenne Section (MS)'), (4, 'Grande Section (GS)'), (5, 'Cours Préparatoire (CP)'), (6, 'Cours Élémentaire 1 (CE1)'), (7, 'Cours Élémentaire 2 (CE2)'), (8, 'Cours Moyen 1 (CM1)'), (9, 'Cours Moyen 2 (CM2)') ] class Speciality(models.Model): name = models.CharField(max_length=100) updated_date = models.DateTimeField(auto_now=True) color_code = models.CharField(max_length=7, default='#FFFFFF') def __str__(self): return self.name class Teacher(models.Model): last_name = models.CharField(max_length=100) first_name = models.CharField(max_length=100) email = models.EmailField(unique=True) specialities = models.ManyToManyField(Speciality, blank=True) associated_profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True, blank=True) updated_date = models.DateTimeField(auto_now=True) def __str__(self): return f"{self.last_name} {self.first_name}" class SchoolClass(models.Model): PLANNING_TYPE_CHOICES = [ (1, 'Annuel'), (2, 'Semestriel'), (3, 'Trimestriel') ] atmosphere_name = models.CharField(max_length=255, null=True, blank=True) age_range = models.JSONField(blank=True) 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=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) time_range = models.JSONField(default=list) opening_days = ArrayField(models.IntegerField(), default=list) def __str__(self): return self.atmosphere_name class Planning(models.Model): level = models.IntegerField(choices=LEVEL_CHOICES, null=True, blank=True) school_class = models.ForeignKey(SchoolClass, null=True, blank=True, related_name='plannings', on_delete=models.CASCADE) schedule = JSONField(default=dict) def __str__(self): return f'Planning for {self.level} of {self.school_class.atmosphere_name}' class PaymentPlanType(models.IntegerChoices): ONE_TIME = 1, '1 fois' THREE_TIMES = 3, '3 fois' TEN_TIMES = 10, '10 fois' TWELVE_TIMES = 12, '12 fois' class DiscountType(models.IntegerChoices): CURRENCY = 0, 'Currency' PERCENT = 1, 'Percent' class FeeType(models.IntegerChoices): REGISTRATION_FEE = 0, 'Registration Fee' TUITION_FEE = 1, 'Tuition Fee' class Discount(models.Model): name = models.CharField(max_length=255, unique=True) amount = models.DecimalField(max_digits=10, decimal_places=2, default=0) description = models.TextField(blank=True) discount_type = models.IntegerField(choices=DiscountType.choices, default=DiscountType.CURRENCY) type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE) updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.name class Fee(models.Model): name = models.CharField(max_length=255, unique=True) base_amount = models.DecimalField(max_digits=10, decimal_places=2, default=0) description = models.TextField(blank=True) is_active = models.BooleanField(default=True) updated_at = models.DateTimeField(auto_now=True) type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE) def __str__(self): return self.name 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)