From 502eab5cf1b6da849b0c852a9a17e14c25a7f4da Mon Sep 17 00:00:00 2001 From: princekumarofficial Date: Sun, 17 Nov 2024 14:23:51 +0530 Subject: [PATCH 1/2] QR: update allocation for every period --- qrscan/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qrscan/views.py b/qrscan/views.py index 28ed0c3..664e953 100644 --- a/qrscan/views.py +++ b/qrscan/views.py @@ -26,9 +26,9 @@ def mess_card(request): mess_card, _ = MessCard.objects.get_or_create(student=student) if(not mess_card.allocation): - setattr(mess_card, allocation) + setattr(mess_card, "allocation", allocation) mess_card.save() - elif((mess_card.allocation != allocation) and allocation.period.end_date < timezone.localtime().date()): + elif((mess_card.allocation != allocation) and mess_card.allocation.period.end_date < timezone.localtime().date()): setattr(mess_card, "allocation", allocation) mess_card.save() From c9ee81f5bb6eb17a5185ed76be5393fc9400296a Mon Sep 17 00:00:00 2001 From: princekumarofficial Date: Sun, 17 Nov 2024 14:32:20 +0530 Subject: [PATCH 2/2] remove unwanted tables --- home/admin.py | 145 ----------- ...23_email_delete_rebateautumn22_and_more.py | 23 ++ home/models/Semesters/autumn22.py | 73 ------ home/models/Semesters/spring23.py | 61 ----- home/models/__init__.py | 6 - home/resources.py | 231 ------------------ 6 files changed, 23 insertions(+), 516 deletions(-) create mode 100644 home/migrations/0002_remove_rebatespring23_email_delete_rebateautumn22_and_more.py delete mode 100644 home/models/Semesters/autumn22.py delete mode 100644 home/models/Semesters/spring23.py diff --git a/home/admin.py b/home/admin.py index c87dcb5..ee37837 100644 --- a/home/admin.py +++ b/home/admin.py @@ -26,8 +26,6 @@ LongRebate, Period, Rebate, - RebateAutumn22, - RebateSpring23, Rule, Scan, Semester, @@ -42,7 +40,6 @@ AllocationResource, CatererBillsResource, LongRebateResource, - RebateBillsResource, RebateResource, StudentBillsResource, StudentResource, @@ -732,148 +729,6 @@ def send_mail(self, request, queryset): } -@admin.register(RebateAutumn22) -class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): - model = RebateAutumn22 - resource_class = RebateBillsResource - search_fields = ( - "email__email", - "email__hostel", - "email__department", - "email__degree", - "email__roll_no", - "email__name", - ) - list_filter = ("email__hostel", "email__department", "email__degree") - list_display = ("__str__", "roll_number", "name", "hostel") - fieldsets = ( - ( - None, - rebate_fields, - ), - ) - - @admin.display(description="roll number") - def roll_number(self, obj): - return obj.email.roll_no - - @admin.display(description="name") - def name(self, obj): - return obj.email.name - - @admin.display(description="hostel") - def hostel(self, obj): - return obj.email.hostel - - @admin.display(description="room number") - def room_number(self, obj): - return obj.email.room_no - - actions = ["export_as_csv"] - - def export_as_csv(self, request, queryset): - """ - Export action available in the admin page - """ - resource = RebateBillsResource() - dataset = resource.export(queryset) - response = HttpResponse(dataset.csv, content_type="text/csv") - response["Content-Disposition"] = 'attachment; filename="RebateAutumn.csv"' - return response - - export_as_csv.short_description = "Export Rebate details to CSV" - - -@admin.register(RebateSpring23) -class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): - resource_class = RebateBillsResource - model = RebateSpring23 - search_fields = ( - "email__email", - "email__hostel", - "email__department", - "email__degree", - "email__roll_no", - "email__name", - ) - list_filter = ("email__hostel", "email__degree", "email__department") - list_display = ("__str__", "roll_number", "name", "hostel") - fieldsets = ( - ( - None, - rebate_fields, - ), - ) - - @admin.display(description="roll number") - def roll_number(self, obj): - return obj.email.roll_no - - @admin.display(description="name") - def name(self, obj): - return obj.email.name - - @admin.display(description="hostel") - def hostel(self, obj): - return obj.email.hostel - - @admin.display(description="room number") - def room_number(self, obj): - return obj.email.room_no - - actions = ["export_as_csv", "clean"] - - @admin.action(description="Clean Null period data") - def clean(self, request, queryset): - """ - Clean testing period data - """ - attributes_to_check = [ - ("period1_short", 0), - ("period1_long", 0), - ("period2_short", 0), - ("period2_long", 0), - ("period3_short", 0), - ("period3_long", 0), - ("period4_short", 0), - ("period4_long", 0), - ("period5_short", 0), - ("period5_long", 0), - ("period6_short", 0), - ("period6_long", 0), - ("period1_high_tea", True), - ("period2_high_tea", True), - ("period3_high_tea", True), - ("period4_high_tea", True), - ("period5_high_tea", True), - ("period6_high_tea", True), - ("period1_bill", 0), - ("period2_bill", 0), - ("period3_bill", 0), - ("period4_bill", 0), - ("period5_bill", 0), - ("period6_bill", 0), - ] - - for obj in queryset: - for attr, default_value in attributes_to_check: - if getattr(obj, attr) is None: - setattr(obj, attr, default_value) - obj.save() - - def export_as_csv(self, request, queryset): - """ - Export action available in the admin page - """ - resource = RebateBillsResource() - dataset = resource.export(queryset) - response = HttpResponse(dataset.csv, content_type="text/csv") - response["Content-Disposition"] = 'attachment; filename="RebateAutumn.csv"' - return response - - export_as_csv.short_description = "Export Rebate details to CSV" - - @admin.register(StudentBills) class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): resource_class = StudentBillsResource diff --git a/home/migrations/0002_remove_rebatespring23_email_delete_rebateautumn22_and_more.py b/home/migrations/0002_remove_rebatespring23_email_delete_rebateautumn22_and_more.py new file mode 100644 index 0000000..7209127 --- /dev/null +++ b/home/migrations/0002_remove_rebatespring23_email_delete_rebateautumn22_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.8 on 2024-11-17 09:01 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='rebatespring23', + name='email', + ), + migrations.DeleteModel( + name='RebateAutumn22', + ), + migrations.DeleteModel( + name='RebateSpring23', + ), + ] diff --git a/home/models/Semesters/autumn22.py b/home/models/Semesters/autumn22.py deleted file mode 100644 index 44d8fb5..0000000 --- a/home/models/Semesters/autumn22.py +++ /dev/null @@ -1,73 +0,0 @@ -from django.db import models -from django.utils.translation import gettext as _ - -from ..students import Student - - -class RebateAutumn22(models.Model): - """ - Storing the Rebate Bills of the Students for the Autumn Semester - """ - - email = models.ForeignKey(Student, on_delete=models.SET_NULL, default="", null=True) - - period1_short = models.IntegerField(_("Period 1 Short"), default=0, null=True) - period1_long = models.IntegerField(_("Period 1 Long"), default=0, null=True) - period1_high_tea = models.BooleanField( - _("Period 1 High Tea"), default=True, null=True - ) - period1_bill = models.IntegerField( - _("Period 1 Rebate Amount"), default=0, null=True - ) - - period2_short = models.IntegerField(_("Period 2 Short"), default=0, null=True) - period2_long = models.IntegerField(_("Period 2 Long"), default=0, null=True) - period2_high_tea = models.BooleanField( - _("Period 2 High Tea"), default=True, null=True - ) - period2_bill = models.IntegerField( - _("Period 2 Rebate Amount"), default=0, null=True - ) - - period3_short = models.IntegerField(_("Period 3 Short"), default=0, null=True) - period3_long = models.IntegerField(_("Period 3 Long"), default=0, null=True) - period3_high_tea = models.BooleanField( - _("Period 3 High Tea"), default=True, null=True - ) - period3_bill = models.IntegerField( - _("Period 3 Rebate Amount"), default=0, null=True - ) - - period4_short = models.IntegerField(_("Period 4 Short"), default=0, null=True) - period4_long = models.IntegerField(_("Period 4 Long"), default=0, null=True) - period4_high_tea = models.BooleanField( - _("Period 4 High Tea"), default=True, null=True - ) - period4_bill = models.IntegerField( - _("Period 4 Rebate Amount"), default=0, null=True - ) - - period5_short = models.IntegerField(_("Period 5 Short"), default=0, null=True) - period5_long = models.IntegerField(_("Period 5 Long"), default=0, null=True) - period5_high_tea = models.BooleanField( - _("Period 5 High Tea"), default=True, null=True - ) - period5_bill = models.IntegerField( - _("Period 5 Rebate Amount"), default=0, null=True - ) - - period6_short = models.IntegerField(_("Period 6 Short"), default=0, null=True) - period6_long = models.IntegerField(_("Period 6 Long"), default=0, null=True) - period6_high_tea = models.BooleanField( - _("Period 6 High Tea"), default=True, null=True - ) - period6_bill = models.IntegerField( - _("Period 6 Rebate Amount"), default=0, null=True - ) - - def __str__(self): - return str(self.email.email) - - class Meta: - verbose_name = "Rebate Bill Autumn 2022" - verbose_name_plural = "Rebate Bills Autumn 2022" diff --git a/home/models/Semesters/spring23.py b/home/models/Semesters/spring23.py deleted file mode 100644 index c56e5c6..0000000 --- a/home/models/Semesters/spring23.py +++ /dev/null @@ -1,61 +0,0 @@ -from django.db import models -from django.utils.translation import gettext as _ - -from ..students import Student - - -class RebateSpring23(models.Model): - """ - Storing the Rebate Bills of the Students for the Spring Semester - """ - - email = models.ForeignKey(Student, on_delete=models.SET_NULL, default="", null=True) - - period1_short = models.IntegerField(_("Period 1 Short"), default=0, null=True) - period1_long = models.IntegerField(_("Period 1 Long"), default=0, null=True) - period1_high_tea = models.BooleanField(_("Period 1 High Tea"), default=True) - period1_bill = models.IntegerField( - _("Period 1 Rebate Amount"), default=0, null=True - ) - - period2_short = models.IntegerField(_("Period 2 Short"), default=0, null=True) - period2_long = models.IntegerField(_("Period 2 Long"), default=0, null=True) - period2_high_tea = models.BooleanField(_("Period 2 High Tea"), default=True) - period2_bill = models.IntegerField( - _("Period 2 Rebate Amount"), default=0, null=True - ) - - period3_short = models.IntegerField(_("Period 3 Short"), default=0, null=True) - period3_long = models.IntegerField(_("Period 3 Long"), default=0, null=True) - period3_high_tea = models.BooleanField(_("Period 3 High Tea"), default=True) - period3_bill = models.IntegerField( - _("Period 3 Rebate Amount"), default=0, null=True - ) - - period4_short = models.IntegerField(_("Period 4 Short"), default=0, null=True) - period4_long = models.IntegerField(_("Period 4 Long"), default=0, null=True) - period4_high_tea = models.BooleanField(_("Period 4 High Tea"), default=True) - period4_bill = models.IntegerField( - _("Period 4 Rebate Amount"), default=0, null=True - ) - - period5_short = models.IntegerField(_("Period 5 Short"), default=0, null=True) - period5_long = models.IntegerField(_("Period 5 Long"), default=0, null=True) - period5_high_tea = models.BooleanField(_("Period 5 High Tea"), default=True) - period5_bill = models.IntegerField( - _("Period 5 Rebate Amount"), default=0, null=True - ) - - period6_short = models.IntegerField(_("Period 6 Short"), default=0, null=True) - period6_long = models.IntegerField(_("Period 6 Long"), default=0, null=True) - period6_high_tea = models.BooleanField(_("Period 6 High Tea"), default=True) - period6_bill = models.IntegerField( - _("Period 6 Rebate Amount"), default=0, null=True - ) - - def __str__(self): - return str(self.email.email) - - class Meta: - verbose_name = "Rebate Bill Spring 2023" - verbose_name_plural = "Rebate Bills Spring 2023" diff --git a/home/models/__init__.py b/home/models/__init__.py index 1ac6463..a6a6388 100644 --- a/home/models/__init__.py +++ b/home/models/__init__.py @@ -9,12 +9,6 @@ from .home import About, Carousel, Update from .links import Form from .rules import Rule, ShortRebate -from .Semesters.autumn22 import ( - RebateAutumn22, -) -from .Semesters.spring23 import ( - RebateSpring23, -) from .students import ( AllocationForm, LeftLongRebate, diff --git a/home/resources.py b/home/resources.py index e6cdd92..de057d6 100644 --- a/home/resources.py +++ b/home/resources.py @@ -10,8 +10,6 @@ LongRebate, Period, Rebate, - RebateAutumn22, - RebateSpring23, Student, StudentBills, UnregisteredStudent, @@ -248,235 +246,6 @@ class Meta: ] -class RebateBillsResource(resources.ModelResource): - email__email = fields.Field( - column_name="Email", - attribute="email__email", - ) - email__roll_no = fields.Field(attribute="email__roll_no", column_name="Roll No.") - email__name = fields.Field(attribute="email__name", column_name="Name") - email__department = fields.Field( - attribute="email__department", column_name="Department" - ) - email__degree = fields.Field( - attribute="email__degree", column_name="Academic Program" - ) - email__hostel = fields.Field(attribute="email__hostel", column_name="Hostel") - email__room_no = fields.Field(attribute="email__room_no", column_name="Room No.") - period1_short = fields.Field( - attribute="period1_short", column_name="Short Rebate 1" - ) - period1_long = fields.Field(attribute="period1_long", column_name="Long Rebate 1") - period1_high_tea = fields.Field( - attribute="period1_high_tea", column_name="High Tea 1" - ) - period1_bill = fields.Field(attribute="period1_bill", column_name="Bill 1") - period2_short = fields.Field( - attribute="period2_short", column_name="Short Rebate 2" - ) - period2_long = fields.Field(attribute="period2_long", column_name="Long Rebate 2") - period2_high_tea = fields.Field( - attribute="period2_high_tea", column_name="High Tea 2" - ) - period2_bill = fields.Field(attribute="period2_bill", column_name="Bill 2") - period3_short = fields.Field( - attribute="period3_short", column_name="Short Rebate 3" - ) - period3_long = fields.Field(attribute="period3_long", column_name="Long Rebate 3") - period3_high_tea = fields.Field( - attribute="period3_high_tea", column_name="High Tea 3" - ) - period3_bill = fields.Field(attribute="period3_bill", column_name="Bill 3") - period4_short = fields.Field( - attribute="period4_short", column_name="Short Rebate 4" - ) - period4_long = fields.Field(attribute="period4_long", column_name="Long Rebate 4") - period4_high_tea = fields.Field( - attribute="period4_high_tea", column_name="High Tea 4" - ) - period4_bill = fields.Field(attribute="period4_bill", column_name="Bill 4") - allocation5 = fields.Field( - attribute="allocation5", column_name="Allocation for period 5" - ) - period5_short = fields.Field( - attribute="period5_short", column_name="Short Rebate 5" - ) - period5_long = fields.Field(attribute="period5_long", column_name="Long Rebate 5") - period5_high_tea = fields.Field( - attribute="period5_high_tea", column_name="High Tea 5" - ) - period5_bill = fields.Field(attribute="period5_bill", column_name="Bill 5") - period6_short = fields.Field( - attribute="period6_short", column_name="Short Rebate 6" - ) - period6_long = fields.Field(attribute="period6_long", column_name="Long Rebate 6") - period6_high_tea = fields.Field( - attribute="period6_high_tea", column_name="High Tea 6" - ) - period6_bill = fields.Field(attribute="period6_bill", column_name="Bill 6") - empty = fields.Field(attribute="empty", column_name="") - last_sem_fee = fields.Field( - attribute="last_sem_fee", column_name="Last Semester Fee" - ) - total = fields.Field(attribute="total", column_name="Total") - upcoming_sem_fee = fields.Field( - attribute="upcoming_sem_fee", column_name="Upcoming Semester Fee" - ) - upcoming_sem_due = fields.Field( - attribute="upcoming_sem_due", column_name="Upcoming Semester Dues" - ) - - def before_import_row(self, row, **kwargs): - # Convert "TRUE" to True for boolean fields - for field_name, field_object in self.fields.items(): - if ( - field_object.column_name - and field_object.column_name.lower() == "true" - or field_object.column_name == 1 - ): - row[field_name] = True - - def skip_row(self, instance, original, row, import_validation_errors): - if not instance.email.name and not instance.email.email: - return True # Skip the row - - return super().skip_row(instance, original, row, import_validation_errors) - - class Meta: - model = RebateAutumn22 - model = RebateSpring23 - exclude = "id" - import_id_fields = ["email__email"] - fields = ( - "email__email", - "email__roll_no", - "email__name", - "email__department", - "email__degree", - "email__hostel", - "email__room_no", - "period1_short", - "period1_long", - "period1_high_tea", - "period1_bill", - "period2_short", - "period2_long", - "period2_high_tea", - "period2_bill", - "period3_short", - "period3_long", - "period3_high_tea", - "period3_bill", - "period4_short", - "period4_long", - "period4_high_tea", - "period4_bill", - "period5_short", - "period5_long", - "period5_high_tea", - "period5_bill", - "period6_short", - "period6_long", - "period6_high_tea", - "period6_bill", - "empty", - "last_sem_fee", - "total", - "upcoming_sem_fee", - "upcoming_sem_due", - ) - export_order = ( - "email__email", - "email__roll_no", - "email__name", - "email__department", - "email__degree", - "email__hostel", - "email__room_no", - "empty", - "period1_short", - "period1_long", - "period1_high_tea", - "period1_bill", - "empty", - "period2_short", - "period2_long", - "period2_high_tea", - "period2_bill", - "empty", - "period3_short", - "period3_long", - "period3_high_tea", - "period3_bill", - "empty", - "period4_short", - "period4_long", - "period4_high_tea", - "period4_bill", - "empty", - "period5_short", - "period5_long", - "period5_high_tea", - "period5_bill", - "empty", - "period6_short", - "period6_long", - "period6_high_tea", - "period6_bill", - "empty", - "last_sem_fee", - "total", - "upcoming_sem_fee", - "upcoming_sem_due", - ) - - def dehydrate_last_sem_fee(self, obj): - try: - fee = Fee.objects.get(program=obj.email.degree) - return fee.prev_sem_fee - except Exception as e: - print(e) - return 0 - - def dehydrate_upcoming_sem_fee(self, obj): - try: - fee = Fee.objects.get(program=obj.email.degree) - return fee.upcoming_sem_fee - except Exception as e: - print(e) - return 0 - - def dehydrate_total(self, obj): - try: - return ( - obj.period1_bill - + obj.period2_bill - + obj.period3_bill - + obj.period4_bill - + obj.period5_bill - + obj.period6_bill - ) - except Exception as e: - print(e) - return 0 - - def dehydrate_upcoming_sem_due(self, obj): - try: - fee = Fee.objects.get(program=obj.email.degree) - return fee.upcoming_sem_fee - ( - fee.prev_sem_fee - - obj.period1_bill - - obj.period2_bill - - obj.period3_bill - - obj.period4_bill - - obj.period5_bill - - obj.period6_bill - ) - except Exception as e: - print(e) - return 0 - - class StudentBillsResource(resources.ModelResource): email__email = fields.Field( column_name="Email",