Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions FusionIIIT/applications/central_mess/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def add_vacation_food_request(request, student):
}
return data

vacation_check = Vacation_food.objects.filter(student_id =student)
vacation_check = Vacation_food.objects.filter(student_id=student).prefetch_related('student_id','student_id__id','student_id__id__user','student_id__id__department')

date_format = "%Y-%m-%d"
b = datetime.strptime(str(start_date), date_format)
Expand Down Expand Up @@ -155,11 +155,8 @@ def add_menu_change_request(request, student):
:return:
"""
try:
print("inside add_menu")
dish = Menu.objects.get(dish=request.POST.get("dish"))
print(dish, "-------------------------------------------------------------------")
new_dish = request.POST.get("newdish")
print(new_dish)
reason = request.POST.get("reason")
# menu_object = Menu_change_request(dish=dish, request=new_dish, reason=reason)
menu_object = Menu_change_request(dish=dish, student_id=student, request=new_dish, reason=reason)
Expand All @@ -172,7 +169,6 @@ def add_menu_change_request(request, student):
data = {
'status': 0
}
print(e)
return data


Expand Down Expand Up @@ -334,9 +330,9 @@ def add_leave_request(request, student):
}
return data

rebates = Rebate.objects.filter(student_id=student)
rebate_check = rebates.filter(Q(status='1') | Q(status='2'))

rebate_check = Rebate.objects.select_related('student_id','student_id__id','student_id__id__user','student_id__id__department').filter(student_id=student, status__in=['1', '2'])

for r in rebate_check:
a = datetime.strptime(str(r.start_date), date_format)
c = datetime.strptime(str(r.end_date), date_format)
Expand Down Expand Up @@ -373,8 +369,8 @@ def add_mess_meeting_invitation(request):
venue = request.POST['venue']
agenda = request.POST['agenda']
time = request.POST['time']
members_mess = HoldsDesignation.objects.filter(Q(designation__name__contains='mess_convener')
| Q(designation__name__contains='mess_committee')|Q(designation__name='mess_manager')
members_mess = HoldsDesignation.objects.select_related().filter(Q(designation__name__contains='mess_convener')
| Q(designation__name__contains='mess_committee')|Q(designation__name='mess_manager')
| Q(designation__name='mess_warden'))
date_today = str(today_g.date())
if date <= date_today:
Expand Down Expand Up @@ -470,8 +466,8 @@ def add_special_food_request(request, student):
return data
spfood_obj = Special_request(student_id=student, start_date=fr, end_date=to,
item1=food1, item2=food2, request=purpose)
requests_food = Special_request.objects.filter(student_id=student)
s_check = requests_food.filter(Q(status='1') | Q(status='2'))
s_check = Special_request.objects.select_related('student_id','student_id__id','student_id__id__user','student_id__id__department').filter(student_id=student,status__in=['1', '2']).order_by('-app_date')


for r in s_check:
a = datetime.strptime(str(r.start_date), date_format)
Expand Down Expand Up @@ -538,17 +534,14 @@ def add_bill_base_amount(request):


def add_mess_committee(request, roll_number):
print("\n\n\\n\n\n\n\n")
print(roll_number)
mess = Messinfo.objects.get(student_id__id=roll_number)
print(mess)
if mess.mess_option == 'mess1':
designation = Designation.objects.get(name='mess_committee_mess1')
else:
designation = Designation.objects.get(name='mess_committee_mess2')
# designation = Designation.objects.get(name='mess_committee')
# add_obj = HoldsDesignation.objects.filter(Q(user__username=roll_number) & Q(designation=designation))
check_obj = HoldsDesignation.objects.filter(Q(user__username=roll_number) &
check_obj=HoldsDesignation.objects.select_related().filter(Q(user__username=roll_number) &
(Q(designation__name__contains='mess_committee')
| Q(designation__name__contains='mess_convener')))
if check_obj:
Expand All @@ -570,18 +563,18 @@ def add_mess_committee(request, roll_number):


def generate_bill():
student_all = Student.objects.all()
month_t = datetime.now().month - 1
month_g = last_day_prev_month.month
first_day_prev_month = last_day_prev_month.replace(day=1)
# previous_month = month_t.strftime("%B")
student_all = Student.objects.prefetch_related('nonveg_data_set','rebate_set')
amount_c = MessBillBase.objects.latest('timestamp')
for student in student_all:
nonveg_total_bill=0
rebate_count = 0
total = 0
nonveg_data = Nonveg_data.objects.filter(student_id=student)
rebates = Rebate.objects.filter(student_id=student)
nonveg_data = student.nonveg_data_set.all()
rebates = student.rebate_set.all()
for order in nonveg_data:
if order.order_date.strftime("%B") == previous_month:
nonveg_total_bill = nonveg_total_bill + order.dish.price
Expand Down Expand Up @@ -609,8 +602,8 @@ def generate_bill():
if Monthly_bill.objects.filter(student_id=student,
month=previous_month,
year = previous_month_year,
total_bill=total):
print("exists")
total_bill=total).exists():
1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this condition required? exists() can be used to check if an object exists.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it won't matter to pass the condition as we have to check if the object is already exist and then do nothing, used the exists() function in the if condition now in the latest commit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove that if condition since its not used to make any changes.

elif Monthly_bill.objects.filter(student_id=student,
month=previous_month,
year = previous_month_year):
Expand Down
1 change: 0 additions & 1 deletion FusionIIIT/applications/central_mess/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,6 @@ def submit_mess_committee(request):
user_details - extract details and designation of the user from the database
"""
roll_number = request.POST['rollnumber']
print(roll_number)
data = add_mess_committee(request, roll_number)
return JsonResponse(data)

Expand Down