Skip to content

Commit

Permalink
fix: left short rebate (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
mittal-ishaan authored Nov 17, 2024
1 parent 9e20a03 commit df70521
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
47 changes: 22 additions & 25 deletions home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import csv
from datetime import timedelta

from django.contrib import admin
from django.http import HttpRequest, HttpResponse
Expand Down Expand Up @@ -34,6 +35,7 @@
UnregisteredStudent,
Update,
)
from home.utils.rebate_checker import max_days_rebate

from .resources import (
AllocationResource,
Expand All @@ -46,12 +48,7 @@
)
from .utils.django_email_server import long_rebate_query_mail
from .utils.month import fill_periods, map_periods_to_long_rebate
from .utils.rebate_bills_saver import (
fix_all_bills,
save_long_bill,
save_short_bill,
update_bills,
)
from .utils.rebate_bills_saver import fix_all_bills, save_long_bill, update_bills

# Customising the heading and title of the admin page
admin.site.site_header = "Dining Website Admin Page"
Expand Down Expand Up @@ -1028,43 +1025,43 @@ class about_Admin(admin.ModelAdmin):
actions = ["Add"]

@admin.action(description="Add left short rebate to Bills")
def Add(self, request, queryset):
def Add(self, request, queryset: list[LeftShortRebate]):
"""
Export action available in the admin page
"""
for obj in queryset:
email = obj.email
student_obj = Student.objects.filter(email=email).last()
for period in Period.objects.all():
if (
period.start_date <= obj.start_date
and period.end_date >= obj.end_date
):
days = (obj.end_date - obj.start_date).days + 1
if period.start_date <= obj.start_date <= period.end_date:
start_date = obj.start_date
end_date = obj.end_date
date_applied = obj.date_applied
if period.end_date < obj.end_date:
obj.start_date = period.end_date + timedelta(days=1)
obj.save()
end_date = period.end_date
else:
obj.delete()
allocation = Allocation.objects.filter(
email=student_obj, period=period
).last()
if allocation:
save_short_bill(
student_obj,
period,
days,
allocation.high_tea,
allocation.caterer,
upper_cap_check = max_days_rebate(
student_obj, start_date, end_date, period
)
print("Saved")
if upper_cap_check == 0:
continue
end_date = start_date + timedelta(days=upper_cap_check - 1)
short_rebate = Rebate(
email=student_obj,
allocation_id=allocation,
start_date=obj.start_date,
end_date=obj.end_date,
date_applied=obj.date_applied,
start_date=start_date,
end_date=end_date,
date_applied=date_applied,
approved=True,
)
short_rebate.save()
LeftShortRebate.objects.filter(
email=email, date_applied=obj.date_applied
).delete()


@admin.register(AllocationForm)
Expand Down
3 changes: 2 additions & 1 deletion home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,12 @@ def rebate(request):
end_date=end_date,
date_applied=date.today(),
)
short_left_rebate.save()
end_date = period_end
upper_cap_check = max_days_rebate(
student, start_date, period_end, period_obj
)
if upper_cap_check < 0:
short_left_rebate.save()
additional_text = " Note: The days after the current period end date will be added to your bills in the next period."
else:
upper_cap_check = max_days_rebate(
Expand Down

0 comments on commit df70521

Please sign in to comment.