mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
feat: Ajout des modes de paiements + création d'une commande dans le
back permettant d'initialiser des données de test (pour les tarifs)
This commit is contained in:
85
Back-End/School/management/commands/init_data.py
Normal file
85
Back-End/School/management/commands/init_data.py
Normal file
@ -0,0 +1,85 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from School.models import Fee, Discount, FeeType, DiscountType
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Initialize or update Fees and Discounts'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
self.create_or_update_fees()
|
||||
self.create_or_update_discounts()
|
||||
|
||||
def create_or_update_fees(self):
|
||||
fees_data = [
|
||||
{
|
||||
"name": "Frais d'inscription",
|
||||
"base_amount": "150.00",
|
||||
"description": "Montant de base",
|
||||
"is_active": True,
|
||||
"type": FeeType.REGISTRATION_FEE
|
||||
},
|
||||
{
|
||||
"name": "Matériel",
|
||||
"base_amount": "85.00",
|
||||
"description": "Livres / jouets",
|
||||
"is_active": True,
|
||||
"type": FeeType.REGISTRATION_FEE
|
||||
},
|
||||
{
|
||||
"name": "Sorties périscolaires",
|
||||
"base_amount": "120.00",
|
||||
"description": "Sorties",
|
||||
"is_active": True,
|
||||
"type": FeeType.REGISTRATION_FEE
|
||||
},
|
||||
{
|
||||
"name": "Les colibris",
|
||||
"base_amount": "4500.00",
|
||||
"description": "TPS / PS / MS / GS",
|
||||
"is_active": True,
|
||||
"type": FeeType.TUITION_FEE
|
||||
},
|
||||
{
|
||||
"name": "Les butterflies",
|
||||
"base_amount": "5000.00",
|
||||
"description": "CP / CE1 / CE2 / CM1 / CM2",
|
||||
"is_active": True,
|
||||
"type": FeeType.TUITION_FEE
|
||||
}
|
||||
]
|
||||
|
||||
for fee_data in fees_data:
|
||||
Fee.objects.update_or_create(
|
||||
name=fee_data["name"],
|
||||
type=fee_data["type"],
|
||||
defaults=fee_data
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Fees initialized or updated successfully'))
|
||||
|
||||
def create_or_update_discounts(self):
|
||||
discounts_data = [
|
||||
{
|
||||
"name": "Parrainage",
|
||||
"amount": "10.00",
|
||||
"description": "Réduction pour parrainage",
|
||||
"discount_type": DiscountType.PERCENT,
|
||||
"type": FeeType.TUITION_FEE
|
||||
},
|
||||
{
|
||||
"name": "Réinscription",
|
||||
"amount": "100.00",
|
||||
"description": "Réduction pour Réinscription",
|
||||
"discount_type": DiscountType.PERCENT,
|
||||
"type": FeeType.REGISTRATION_FEE
|
||||
}
|
||||
]
|
||||
|
||||
for discount_data in discounts_data:
|
||||
Discount.objects.update_or_create(
|
||||
name=discount_data["name"],
|
||||
type=discount_data["type"],
|
||||
discount_type=discount_data["discount_type"],
|
||||
defaults=discount_data
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Discounts initialized or updated successfully'))
|
||||
25
Back-End/School/management/commands/init_payment_modes.py
Normal file
25
Back-End/School/management/commands/init_payment_modes.py
Normal file
@ -0,0 +1,25 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from School.models import PaymentMode, PaymentModeType, FeeType
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Initialize or update Payment Modes'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
self.create_or_update_payment_modes()
|
||||
|
||||
def create_or_update_payment_modes(self):
|
||||
for fee_type in FeeType.choices:
|
||||
fee_type_value = fee_type[0]
|
||||
|
||||
for mode in PaymentModeType.choices:
|
||||
mode_value = mode[0]
|
||||
|
||||
PaymentMode.objects.update_or_create(
|
||||
mode=mode_value,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'is_active': False
|
||||
}
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Payment Modes initialized or updated successfully'))
|
||||
Reference in New Issue
Block a user