Skip to content

Commit

Permalink
Merge pull request #25 from DaemonLab/docker
Browse files Browse the repository at this point in the history
Docker
  • Loading branch information
mittal-ishaan authored Jun 19, 2023
2 parents 791bd73 + 17dcac0 commit 389236b
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 98 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
.vscode

__pycache__
migrations
db.sqlite3
59 changes: 42 additions & 17 deletions home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
PeriodSpring23,
PeriodAutumn23,
LeftLongRebate,
LeftShortRebate,
AllocationForm,
)
from import_export.admin import ImportExportModelAdmin, ImportExportMixin
Expand Down Expand Up @@ -72,9 +73,7 @@
CONTACT_DESC_TEXT = "This contains the content that will show up in the contact page. Add new field for each new contact."
ALLOCATION_DESC_TEXT = "This contains the Allocation details of the students. First import data through /allocation/ url then export"
STUDENT_DESC_TEXT = "This contains the Basic details of each students."
REBATE_DESC_TEXT = (
"This contains the rebate details of each rebate applied by the students."
)
REBATE_DESC_TEXT = "This contains the rebate details of each rebate applied by the students."
REBATE_BILLS_DESC_TEXT = "This contains the rebate bills of each students."

# Register your models here
Expand Down Expand Up @@ -1102,6 +1101,45 @@ def Add(self, request, queryset):
days_per_period = fill_periods(student,obj.start_date, obj.end_date)
save_long_bill(student, days_per_period,1)

@admin.register(LeftShortRebate)
class about_Admin(admin.ModelAdmin):
model = LeftShortRebate
search_fields = ("email",)
list_display = ("email", "start_date", "end_date")
fieldsets = (
(None,{"fields": ("email", "start_date", "end_date","date_applied")},),)

actions = ["Add"]

@admin.action(description="Add left short rebate to Bills")
def Add(self, request, queryset):
"""
Export action available in the admin page
"""
for obj in queryset:
email = obj.email
for period in PeriodSpring23.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
allocation=AllocationSpring23.objects.filter(roll_no__email=email,month=period).last()
if allocation:
save_short_bill(email,period,days,allocation.caterer_name,allocation.high_tea,1)
new_rebate = TodayRebate(date=obj.date_applied,Caterer=allocation.caterer_name,allocation_id = allocation,start_date=obj.start_date,end_date=obj.end_date)
new_rebate.save()
print("Saved")
rebate_mail(obj.start_date,obj.end_date,obj.approved,email)
short_rebate = Rebate(
email=email,
allocation_id=allocation,
start_date=obj.start_date,
end_date=obj.end_date,
date_applied=obj.date_applied,
approved=True,
)
short_rebate.save()
LeftShortRebate.objects.filter(email=email, date_applied = obj.date_applied).delete()


@admin.register(AllocationForm)
class about_Admin(ImportExportModelAdmin,admin.ModelAdmin):
# resource_class = AllocationFormResource
Expand All @@ -1122,17 +1160,4 @@ class about_Admin(ImportExportModelAdmin,admin.ModelAdmin):
)
},
),
)

actions = ["Add"]

@admin.action(description="Add left long rebate to Bills")
def Add(self, request, queryset):
"""
Export action available in the admin page
"""
for obj in queryset:
email = obj.email
student = Student.objects.filter(email=email).last()
days_per_period = fill_periods(student,obj.start_date, obj.end_date)
save_long_bill(student, days_per_period,1)
)
3 changes: 2 additions & 1 deletion home/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
Used to send All Caterers Information as context in the base template
'''
def base(request):
return {'all_caterer' : Caterer.objects.all()}
caterer = Caterer.objects.filter(visible=True).all()
return {'all_caterer' : caterer}
36 changes: 36 additions & 0 deletions home/migrations/0046_caterer_visible_allocationform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 4.1.7 on 2023-06-14 15:46

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('home', '0045_alter_rebateautumn22_period1_high_tea_and_more'),
]

operations = [
migrations.AddField(
model_name='caterer',
name='visible',
field=models.BooleanField(default=False, help_text='If the caterer is visible or not to the students', null=True, verbose_name='Visible'),
),
migrations.CreateModel(
name='AllocationForm',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('heading', models.CharField(blank=True, default='', max_length=100, null=True, verbose_name='heading')),
('description', models.TextField(blank=True, default='', null=True, verbose_name='description')),
('active', models.BooleanField(blank=True, default=False, null=True, verbose_name='active')),
('start_time', models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True, verbose_name='Start Time')),
('end_time', models.DateTimeField(blank=True, null=True, verbose_name='End Time')),
('period', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='home.periodspring23')),
],
options={
'verbose_name': 'Allocation Form',
'verbose_name_plural': 'Allocation Form',
},
),
]
28 changes: 28 additions & 0 deletions home/migrations/0047_leftshortrebate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.1.7 on 2023-06-14 15:47

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('home', '0046_caterer_visible_allocationform'),
]

operations = [
migrations.CreateModel(
name='LeftShortRebate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.CharField(default='', max_length=30, verbose_name='email')),
('start_date', models.DateField(blank=True, help_text='start date of the rebate', null=True)),
('end_date', models.DateField(blank=True, help_text='end date of the rebate', null=True)),
('date_applied', models.DateField(default=django.utils.timezone.now, help_text='Date on which the rebate was applied')),
],
options={
'verbose_name': 'Left Short Rebate',
'verbose_name_plural': 'Left Short Rebate',
},
),
]
2 changes: 1 addition & 1 deletion home/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .home import About, Carousel, Update
from .links import Form
from .rules import Rule, ShortRebate
from .students import Student, Scan, Rebate, LongRebate, UnregisteredStudent, TodayRebate, LeftLongRebate, AllocationForm
from .students import Student, Scan, Rebate, LongRebate, UnregisteredStudent, TodayRebate, LeftLongRebate, LeftShortRebate, AllocationForm
from .Semesters.autumn22 import PeriodAutumn22, AllocationAutumn22, RebateAutumn22, CatererBillsAutumn22
from .Semesters.spring23 import PeriodSpring23, AllocationSpring23, RebateSpring23, CatererBillsSpring23
from .Semesters.autumn23 import PeriodAutumn23, AllocationAutumn23, RebateAutumn23, CatererBillsAutumn23
13 changes: 13 additions & 0 deletions home/models/students.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ class Meta:
verbose_name = "Left Long Rebate"
verbose_name_plural = "Left Long Rebate"

class LeftShortRebate(models.Model):
email = models.CharField(_("email"), max_length=30, default="")
start_date = models.DateField(help_text="start date of the rebate",null=True, blank=True)
end_date = models.DateField(help_text="end date of the rebate",null=True, blank=True)
date_applied = models.DateField(help_text="Date on which the rebate was applied",default=now)

def __str__(self):
return str(self.email)

class Meta:
verbose_name = "Left Short Rebate"
verbose_name_plural = "Left Short Rebate"

class AllocationForm(models.Model):
from .Semesters.spring23 import PeriodSpring23
heading = models.CharField(_("heading"), max_length=100, default="",null=True, blank=True)
Expand Down
2 changes: 1 addition & 1 deletion home/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def update_long_bill(sender, instance, **kwargs):
print(e)

@receiver(post_save, sender=AllocationSpring23)
def update_spring_bill(sender, instance, created, **kwargs):
def update_rebate_bill(sender, instance, created, **kwargs):
try:
if created:
sno = instance.month.Sno
Expand Down
4 changes: 2 additions & 2 deletions home/utils/rebate_bills_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def save_short_bill(email,period,days,high_tea,caterer):
rebate.period6_high_tea = high_tea
rebate.period6_short = rebate.period6_short + days
rebate.period6_bill = rebate.period6_bill - amount
catererBill.period6_bills = catererBill.period5_bills + amount
catererBill.period6_bills = catererBill.period6_bills + amount
rebate.save()
catererBill.save()

Expand Down Expand Up @@ -109,7 +109,7 @@ def save_long_bill(email,days_per_period,j):
rebate.period6_high_tea = allocation.high_tea
rebate.period6_long = rebate.period6_long + days
rebate.period6_bill = rebate.period6_bill - amount
catererBill.period6_bills = catererBill.period5_bills + amount
catererBill.period6_bills = catererBill.period6_bills + amount
rebate.save()
catererBill.save()
case 7:
Expand Down
8 changes: 2 additions & 6 deletions home/utils/rebate_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ def count(start, end):
sum = ((end - start).days) + 1
return sum

def is_not_duplicate(s,start,end,period):
def is_not_duplicate(s,start,end):
"""Checks if these dates are already applied for rebate"""
try:
short = Rebate.objects.filter(email=str(s.email)).last()
long = LongRebate.objects.filter(email=s).last()
if(short==None or short.allocation_id==None):
prev_period = 0
else:
prev_period = short.allocation_id.month.Sno
print("is_not_duplicate")
print(short)
print(long)
if (short==None or short.end_date<= start-timedelta(days=2) or short.start_date>=end+timedelta(days=2) or period!=prev_period) and (long==None or long.end_date<= start-timedelta(days=2) or long.start_date>=end+timedelta(days=2)):
if (short==None or short.end_date<= start-timedelta(days=2) or short.start_date>=end+timedelta(days=2)) and (long==None or long.end_date<= start-timedelta(days=2) or long.start_date>=end+timedelta(days=2)):
return True
else:
return False
Expand Down
Loading

0 comments on commit 389236b

Please sign in to comment.