@@ -151,117 +151,108 @@ def rebate(request):
151151
152152 :template:`rebateForm.html`
153153 """
154- text = ""
155- list = []
154+ message = ""
156155 period_obj = None
157- allocation_id = None
156+ allocation = None
158157 try :
159- student = Student .objects .filter (email__iexact = str (request .user .email ))
160- try :
161- for period in Period .objects .all ():
162- if period .end_date > date .today () + timedelta (1 ):
163- period_obj = period
164- try :
165- allocation_id = Allocation .objects .get (
166- email__email__iexact = str (request .user .email ), period = period
167- )
168- break
169- except :
170- continue
171- key = str (allocation_id .student_id )
172- except Exception as e :
173- logger .error (e )
174- key = "You are not allocated for current period, please contact the dining warden to allocate you to a caterer"
158+ student = Student .objects .get (email__iexact = request .user .email )
175159 except Student .DoesNotExist :
176- key = "Signed in account does not does not have any allocation ID"
160+ message = "Signed in account does not have any allocation ID"
161+ return render (request , "rebateForm.html" , {"text" : message })
162+
163+ try :
164+ period_obj = next (
165+ period
166+ for period in Period .objects .all ()
167+ if period .end_date > date .today () + timedelta (1 )
168+ )
169+ allocation = Allocation .objects .get (
170+ email__iexact = request .user .email , period = period_obj
171+ )
172+ except Exception as e :
173+ logger .error (e )
174+ message = "You are not allocated for current period, please contact the dining warden to allocate you to a caterer"
177175 if request .method == "POST" and request .user .is_authenticated :
178- if not period_obj or not allocation_id :
179- text = "You are not allocated for current period, please contact the dining warden to allocate you to a caterer"
180- request .session ["text" ] = text
176+ if not period_obj or not allocation :
177+ message = "You are not allocated for current period, please contact the dining warden to allocate you to a caterer"
178+ request .session ["text" ] = message
181179 return redirect (request .path )
180+
182181 try :
183182 start_date = parse_date (request .POST ["start_date" ])
184183 end_date = parse_date (request .POST ["end_date" ])
185184 rebate_days = ((end_date - start_date ).days ) + 1
186185 before_rebate_days = (start_date - date .today ()).days
187- try :
188- student = Student .objects .filter (
189- email__iexact = str (request .user .email )
190- ).first ()
191- period = period_obj .Sno
192- period_start = period_obj .start_date
193- period_end = period_obj .end_date
194- if rebate_days > 7 :
195- text = "Max no of days for rebate is 7"
196- elif before_rebate_days < 2 :
197- text = "Form needs to be filled atleast 2 days prior the comencement of leave."
198- elif not is_not_duplicate (student , start_date , end_date ):
199- text = "You have already applied for rebate during this duration"
200- elif 0 < rebate_days < 2 :
201- text = "Min no of days for rebate is 2"
202- else :
203- additional_text = ""
204- if not period_start <= start_date <= period_end :
205- short_left_rebate = LeftShortRebate (
206- email = student .email ,
207- start_date = start_date ,
208- end_date = end_date ,
209- date_applied = date .today (),
210- )
186+
187+ if rebate_days > 7 :
188+ message = "Max no of days for rebate is 7"
189+ elif before_rebate_days < 2 :
190+ message = "Form needs to be filled atleast 2 days prior the comencement of leave."
191+ elif not is_not_duplicate (student , start_date , end_date ):
192+ message = "You have already applied for rebate during this duration"
193+ elif 0 < rebate_days < 2 :
194+ message = "Min no of days for rebate is 2"
195+ else :
196+ additional_message = ""
197+ if not period_obj .start_date <= start_date <= period_obj .end_date :
198+ short_left_rebate = LeftShortRebate (
199+ email = student .email ,
200+ start_date = start_date ,
201+ end_date = end_date ,
202+ date_applied = date .today (),
203+ )
204+ short_left_rebate .save ()
205+ message = "You have successfully submitted the rebate, it will get added to your bills in the next period."
206+ upper_cap_check = - 1
207+ elif not period_obj .start_date <= end_date <= period_obj .end_date :
208+ short_left_rebate = LeftShortRebate (
209+ email = student .email ,
210+ start_date = period_obj .end_date + timedelta (days = 1 ),
211+ end_date = end_date ,
212+ date_applied = date .today (),
213+ )
214+ end_date = period_obj .end_date
215+ upper_cap_check = max_days_rebate (
216+ student , start_date , period_obj .end_date , period_obj
217+ )
218+ if upper_cap_check < 0 :
211219 short_left_rebate .save ()
212- text = "You have successfully submitted the rebate, it will get added to your bills in the next period."
213- upper_cap_check = - 1
214- elif not period_start <= end_date <= period_end :
215- short_left_rebate = LeftShortRebate (
216- email = student .email ,
217- start_date = period_end + timedelta (days = 1 ),
218- end_date = end_date ,
219- date_applied = date .today (),
220- )
221- end_date = period_end
222- upper_cap_check = max_days_rebate (
223- student , start_date , period_end , period_obj
224- )
225- if upper_cap_check < 0 :
226- short_left_rebate .save ()
227- additional_text = " Note: The days after the current period end date will be added to your bills in the next period."
228- else :
229- upper_cap_check = max_days_rebate (
230- student , start_date , end_date , period_obj
231- )
232- if upper_cap_check >= 0 :
233- text = (
234- "You can only apply for max 8 days in a period. Days left for this period: "
235- + str (upper_cap_check )
236- )
237- elif text == "" :
238- r = Rebate (
239- email = student ,
240- allocation_id = allocation_id ,
241- start_date = start_date ,
242- end_date = end_date ,
243- approved = True ,
244- )
245- r .save ()
246- text = "You have successfully submitted the rebate. Thank You! You shall recieve a confirmation mail, If not please contact the Dining Warden."
247- if additional_text :
248- text += additional_text
249- elif not text :
250- text = "Your rebate application has been rejected due to non-compliance of the short term rebate rules"
251- except Allocation .DoesNotExist :
252- text = "Email ID does not match with the allocation ID"
220+ additional_message = " Note: The days after the current period end date will be added to your bills in the next period."
221+ else :
222+ upper_cap_check = max_days_rebate (
223+ student , start_date , end_date , period_obj
224+ )
225+ if upper_cap_check >= 0 :
226+ message = (
227+ "You can only apply for max 8 days in a period. Days left for this period: "
228+ + str (upper_cap_check )
229+ )
230+ elif not message :
231+ rebate = Rebate (
232+ email = student ,
233+ allocation_id = allocation ,
234+ start_date = start_date ,
235+ end_date = end_date ,
236+ approved = True ,
237+ )
238+ rebate .save ()
239+ message = "You have successfully submitted the rebate. Thank You! You shall recieve a confirmation mail, If not please contact the Dining Warden."
240+ if additional_message :
241+ message += additional_message
242+ elif not message :
243+ message = "Your rebate application has been rejected due to non-compliance of the short term rebate rules"
253244 except Exception as e :
254245 logger .error (e )
255- text = (
246+ message = (
256247 "Ohh No! an unknown ERROR occured, Please inform about it immediatly to the Dining Wadern. Possible Error: "
257- + key
248+ + str ( e )
258249 )
259- request .session ["text" ] = text
250+ request .session ["text" ] = message
260251 return redirect (request .path )
261252 text = request .session .get ("text" , "" )
262253 if text != "" :
263254 del request .session ["text" ]
264- context = {"text" : text , "key" : key , "list" : list }
255+ context = {"text" : text , "key" : allocation . student_id }
265256 return render (request , "rebateForm.html" , context )
266257
267258
@@ -336,7 +327,7 @@ def addLongRebateBill(request):
336327 text = "Long Term rebate added Successfully"
337328 except Exception as e :
338329 text = "An error occurred while processing your form submission. If you're submitting an application, try compressing it before resubmitting. If the issue persists, please report it to the admin."
339- print (e )
330+ logger . error (e )
340331 except Exception as e :
341332 logger .error (e )
342333 text = "Email ID does not exist in the database. Please login using the correct email ID"
0 commit comments