@@ -188,6 +188,7 @@ def check_status(request):
188188def check_tender_status (request ):
189189 tender = request .validated ["tender" ]
190190 now = get_now ()
191+
191192 if tender .lots :
192193 if any ([i .status in tender .block_complaint_status and i .relatedLot is None for i in tender .complaints ]):
193194 return
@@ -204,7 +205,7 @@ def check_tender_status(request):
204205 pending_awards_complaints = any (
205206 [i .status in tender .block_complaint_status for a in lot_awards for i in a .complaints ]
206207 )
207- stand_still_end = max ([a .complaintPeriod . endDate or now for a in lot_awards ])
208+ stand_still_end = max ([( a .complaintPeriod and a . complaintPeriod . endDate ) or now for a in lot_awards ])
208209 if pending_complaints or pending_awards_complaints or not stand_still_end <= now :
209210 continue
210211 elif last_award .status == "unsuccessful" :
@@ -214,14 +215,20 @@ def check_tender_status(request):
214215 )
215216 lot .status = "unsuccessful"
216217 continue
217- elif last_award .status == "active" and any (
218- [i .status == "active" and i .awardID == last_award .id for i in tender .contracts ]
219- ):
220- LOGGER .info (
221- "Switched lot {} of tender {} to {}" .format (lot .id , tender .id , "complete" ),
222- extra = context_unpack (request , {"MESSAGE_ID" : "switched_lot_complete" }, {"LOT_ID" : lot .id }),
218+ elif last_award .status == "active" :
219+ active_contracts = (
220+ [a .status == "active" for a in tender .agreements ]
221+ if "agreements" in tender
222+ else [i .status == "active" and i .awardID == last_award .id for i in tender .contracts ]
223223 )
224- lot .status = "complete"
224+
225+ if any (active_contracts ):
226+ LOGGER .info (
227+ "Switched lot {} of tender {} to {}" .format (lot .id , tender .id , "complete" ),
228+ extra = context_unpack (request , {"MESSAGE_ID" : "switched_lot_complete" }, {"LOT_ID" : lot .id }),
229+ )
230+ lot .status = "complete"
231+
225232 statuses = set ([lot .status for lot in tender .lots ])
226233 if statuses == set (["cancelled" ]):
227234 LOGGER .info (
@@ -261,7 +268,13 @@ def check_tender_status(request):
261268 extra = context_unpack (request , {"MESSAGE_ID" : "switched_tender_unsuccessful" }),
262269 )
263270 tender .status = "unsuccessful"
264- if tender .contracts and tender .contracts [- 1 ].status == "active" :
271+
272+ contracts = (
273+ tender .agreements [- 1 ].get ("contracts" )
274+ if tender .get ("agreements" )
275+ else tender .get ("contracts" , [])
276+ )
277+ if contracts and contracts [- 1 ].status == "active" :
265278 tender .status = "complete"
266279 if tender .procurementMethodType == "belowThreshold" :
267280 check_ignored_claim (tender )
0 commit comments