@@ -150,14 +150,29 @@ def status() -> ApplicationSectionStatusChoice:
150150 models .Q (application__application_round__application_period_end__gte = Now ()),
151151 then = models .Value (ApplicationSectionStatusChoice .UNALLOCATED .value ),
152152 ),
153+ models .When (
154+ # Application round has moved to handled stage
155+ # AND there are no allocated reservation unit options
156+ # OR Application round has NOT moved to rejected stage
157+ # AND all reservation unit options have been locked or rejected
158+ condition = (
159+ models .Q (
160+ models .Q (application__application_round__handled_date__isnull = False )
161+ & models .Q (L (allocations = 0 ))
162+ )
163+ | models .Q (
164+ models .Q (application__application_round__handled_date__isnull = True )
165+ & models .Q (L (usable_reservation_unit_options = 0 ))
166+ )
167+ ),
168+ then = models .Value (ApplicationSectionStatusChoice .REJECTED .value ),
169+ ),
153170 models .When (
154171 # Application round has moved to handled stage
155172 # OR number of allocations equals the number of applied reservations per week
156- # OR all reservation unit options have been locked or rejected
157173 condition = (
158174 models .Q (application__application_round__handled_date__isnull = False )
159175 | models .Q (L (allocations__gte = models .F ("applied_reservations_per_week" )))
160- | models .Q (L (usable_reservation_unit_options = 0 ))
161176 ),
162177 then = models .Value (ApplicationSectionStatusChoice .HANDLED .value ),
163178 ),
@@ -182,12 +197,15 @@ def _(self) -> ApplicationSectionStatusChoice:
182197 total_allocations = sum (option .num_of_allocations for option in reservation_unit_options )
183198 all_locked_or_rejected = all (option .locked or option .rejected for option in reservation_unit_options )
184199
185- if self .application .application_round .status .past_allocation :
186- return ApplicationSectionStatusChoice .HANDLED
187200 if total_allocations >= self .applied_reservations_per_week :
188201 return ApplicationSectionStatusChoice .HANDLED
189202 if all_locked_or_rejected :
190- return ApplicationSectionStatusChoice .HANDLED
203+ return ApplicationSectionStatusChoice .REJECTED
204+
205+ if self .application .application_round .status .past_allocation :
206+ if total_allocations >= 1 :
207+ return ApplicationSectionStatusChoice .HANDLED
208+ return ApplicationSectionStatusChoice .REJECTED
191209
192210 return ApplicationSectionStatusChoice .IN_ALLOCATION
193211
@@ -248,9 +266,13 @@ def status_sort_order() -> int:
248266 then = models .Value (2 ),
249267 ),
250268 models .When (
251- models .Q (L (status = ApplicationSectionStatusChoice .HANDLED .value )),
269+ models .Q (L (status = ApplicationSectionStatusChoice .REJECTED .value )),
252270 then = models .Value (3 ),
253271 ),
254- default = models .Value (6 ),
272+ models .When (
273+ models .Q (L (status = ApplicationSectionStatusChoice .HANDLED .value )),
274+ then = models .Value (4 ),
275+ ),
276+ default = models .Value (5 ),
255277 output_field = models .IntegerField (),
256278 )
0 commit comments