From 28f444b05b88605bb82e56d45cf8eb1b55fb9711 Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Tue, 26 Sep 2023 18:53:06 +0530 Subject: [PATCH] caterer bills table generation action --- home/admin.py | 11 ++++++++++- home/signals.py | 11 +++++++++-- home/views.py | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/home/admin.py b/home/admin.py index 1d4a3d0..e2a6c35 100644 --- a/home/admin.py +++ b/home/admin.py @@ -185,6 +185,16 @@ class about_Admin(admin.ModelAdmin): ), ) # In future can create an admin action to directly generate the table for caterer v=bills for a semester. + actions = ["generate_table"] + + @admin.action(description="Generate the table for caterer Bills") + def generate_table(self,request,queryset): + semester = Semester.objects.filter().last() + for caterer in queryset: + caterer_bill,_ = CatererBills.objects.get_or_create(caterer=caterer,semester=semester) + caterer_bill.save() + + @admin.register(Form) class about_Admin(admin.ModelAdmin): @@ -1119,7 +1129,6 @@ class about_admin(admin.ModelAdmin): (None,{"fields": ("name",)},),) - @admin.register(Fee) class about_Admin(admin.ModelAdmin): model = Fee diff --git a/home/signals.py b/home/signals.py index 9be2f0c..774df10 100644 --- a/home/signals.py +++ b/home/signals.py @@ -30,7 +30,6 @@ def update_bill(sender, instance, created, **kwargs): start_date= instance.start_date end_date = instance.end_date days = count(start_date, end_date) - print("Signal called for Short Rebate") save_short_bill(email,allocation.period,days,allocation.high_tea, allocation.caterer) new_rebate = TodayRebate(date=instance.date_applied,Caterer=allocation.caterer.name,allocation_id = allocation,start_date=start_date,end_date=end_date) new_rebate.save() @@ -123,4 +122,12 @@ def create_unregistered(sender, instance,created, **kwargs): for student in Student.objects.all(): unregistered,_ = UnregisteredStudent.objects.get_or_create(email=str(student.email)) unregistered.period = instance - unregistered.save() \ No newline at end of file + unregistered.save() + +@receiver(post_save, sender=Semester) +def create_catererBills(sender, instance, created, **kwargs): + if created: + caterer = instance.name + semester = Semester.objects.filter().last() + caterer_bill,_ = CatererBills.objects.get_or_create(caterer=caterer,semester=semester) + caterer_bill.save() \ No newline at end of file diff --git a/home/views.py b/home/views.py index 2e49c49..f52ce37 100644 --- a/home/views.py +++ b/home/views.py @@ -150,7 +150,7 @@ def rebate(request): period = period_obj ) key = str(allocation_id.student_id) - except: + except Exception as e: key="You are not allocated for current period, please contact the dining warden to allocate you to a caterer" except Student.DoesNotExist: key = "Signed in account does not does not have any allocation ID"