Skip to content

Commit

Permalink
Merge branch 'a157335104845450_next_check'
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Aug 15, 2016
2 parents 0b955b8 + e17701c commit 934f857
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 61 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

setup(name='openprocurement.api',
version='2.3.11',
version='2.3.17',
description='openprocurement.api',
long_description=README,
classifiers=[
Expand Down
42 changes: 28 additions & 14 deletions src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ def __local_roles__(self):
create_accreditation = 1
edit_accreditation = 2
procuring_entity_kinds = ['general', 'special', 'defense', 'other']
block_complaint_status = ['claim', 'answered', 'pending']

__name__ = ''

Expand Down Expand Up @@ -1211,34 +1212,47 @@ def next_check(self):
checks.append(lot.auctionPeriod.startDate.astimezone(TZ))
elif now < calc_auction_end_time(lot.numberOfBids, lot.auctionPeriod.startDate).astimezone(TZ):
checks.append(calc_auction_end_time(lot.numberOfBids, lot.auctionPeriod.startDate).astimezone(TZ))
elif not self.lots and self.status == 'active.awarded':
elif not self.lots and self.status == 'active.awarded' and not any([
i.status in self.block_complaint_status
for i in self.complaints
]) and not any([
i.status in self.block_complaint_status
for a in self.awards
for i in a.complaints
]):
standStillEnds = [
a.complaintPeriod.endDate.astimezone(TZ)
for a in self.awards
if a.complaintPeriod.endDate
]
if standStillEnds:
standStillEnd = max(standStillEnds)
if standStillEnd > now:
checks.append(standStillEnd)
elif self.lots and self.status in ['active.qualification', 'active.awarded']:
lots_ends = []
last_award_status = self.awards[-1].status if self.awards else ''
if standStillEnds and last_award_status == 'unsuccessful':
checks.append(max(standStillEnds))
elif self.lots and self.status in ['active.qualification', 'active.awarded'] and not any([
i.status in self.block_complaint_status and i.relatedLot is None
for i in self.complaints
]):
for lot in self.lots:
if lot['status'] != 'active':
continue
lot_awards = [i for i in self.awards if i.lotID == lot.id]
pending_complaints = any([
i['status'] in self.block_complaint_status and i.relatedLot == lot.id
for i in self.complaints
])
pending_awards_complaints = any([
i.status in self.block_complaint_status
for a in lot_awards
for i in a.complaints
])
standStillEnds = [
a.complaintPeriod.endDate.astimezone(TZ)
for a in lot_awards
if a.complaintPeriod.endDate
]
if not standStillEnds:
continue
standStillEnd = max(standStillEnds)
if standStillEnd > now:
lots_ends.append(standStillEnd)
if lots_ends:
checks.append(min(lots_ends))
last_award_status = lot_awards[-1].status if lot_awards else ''
if not pending_complaints and not pending_awards_complaints and standStillEnds and last_award_status == 'unsuccessful':
checks.append(max(standStillEnds))
if self.status.startswith('active'):
from openprocurement.api.utils import calculate_business_date
for complaint in self.complaints:
Expand Down
69 changes: 23 additions & 46 deletions src/openprocurement/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,26 +370,9 @@ def check_status(request):
return
standStillEnd = max(standStillEnds)
if standStillEnd <= now:
pending_complaints = any([
i['status'] in ['claim', 'answered', 'pending']
for i in tender.complaints
])
pending_awards_complaints = any([
i['status'] in ['claim', 'answered', 'pending']
for a in tender.awards
for i in a.complaints
])
awarded = any([
i['status'] == 'active'
for i in tender.awards
])
if not pending_complaints and not pending_awards_complaints and not awarded:
LOGGER.info('Switched tender {} to {}'.format(tender.id, 'unsuccessful'),
extra=context_unpack(request, {'MESSAGE_ID': 'switched_tender_unsuccessful'}))
check_tender_status(request)
return
check_tender_status(request)
elif tender.lots and tender.status in ['active.qualification', 'active.awarded']:
if any([i['status'] in ['claim', 'answered', 'pending'] and i.relatedLot is None for i in tender.complaints]):
if any([i['status'] in tender.block_complaint_status and i.relatedLot is None for i in tender.complaints]):
return
for lot in tender.lots:
if lot['status'] != 'active':
Expand All @@ -404,30 +387,15 @@ def check_status(request):
continue
standStillEnd = max(standStillEnds)
if standStillEnd <= now:
pending_complaints = any([
i['status'] in ['claim', 'answered', 'pending'] and i.relatedLot == lot.id
for i in tender.complaints
])
pending_awards_complaints = any([
i['status'] in ['claim', 'answered', 'pending']
for a in lot_awards
for i in a.complaints
])
awarded = any([
i['status'] == 'active'
for i in lot_awards
])
if not pending_complaints and not pending_awards_complaints and not awarded:
LOGGER.info('Switched lot {} of tender {} to {}'.format(lot['id'], tender.id, 'unsuccessful'),
extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_unsuccessful'}, {'LOT_ID': lot['id']}))
check_tender_status(request)
check_tender_status(request)
return


def check_tender_status(request):
tender = request.validated['tender']
now = get_now()
if tender.lots:
if any([i.status in ['claim', 'answered', 'pending'] and i.relatedLot is None for i in tender.complaints]):
if any([i.status in tender.block_complaint_status and i.relatedLot is None for i in tender.complaints]):
return
for lot in tender.lots:
if lot.status != 'active':
Expand All @@ -437,11 +405,11 @@ def check_tender_status(request):
continue
last_award = lot_awards[-1]
pending_complaints = any([
i['status'] in ['claim', 'answered', 'pending'] and i.relatedLot == lot.id
i['status'] in tender.block_complaint_status and i.relatedLot == lot.id
for i in tender.complaints
])
pending_awards_complaints = any([
i.status in ['claim', 'answered', 'pending']
i.status in tender.block_complaint_status
for a in lot_awards
for i in a.complaints
])
Expand All @@ -452,24 +420,34 @@ def check_tender_status(request):
if pending_complaints or pending_awards_complaints or not stand_still_end <= now:
continue
elif last_award.status == 'unsuccessful':
LOGGER.info('Switched lot {} of tender {} to {}'.format(lot.id, tender.id, 'unsuccessful'),
extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_unsuccessful'}, {'LOT_ID': lot.id}))
lot.status = 'unsuccessful'
continue
elif last_award.status == 'active' and any([i.status == 'active' and i.awardID == last_award.id for i in tender.contracts]):
LOGGER.info('Switched lot {} of tender {} to {}'.format(lot.id, tender.id, 'complete'),
extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_complete'}, {'LOT_ID': lot.id}))
lot.status = 'complete'
statuses = set([lot.status for lot in tender.lots])
if statuses == set(['cancelled']):
LOGGER.info('Switched tender {} to {}'.format(tender.id, 'cancelled'),
extra=context_unpack(request, {'MESSAGE_ID': 'switched_tender_cancelled'}))
tender.status = 'cancelled'
elif not statuses.difference(set(['unsuccessful', 'cancelled'])):
LOGGER.info('Switched tender {} to {}'.format(tender.id, 'unsuccessful'),
extra=context_unpack(request, {'MESSAGE_ID': 'switched_tender_unsuccessful'}))
tender.status = 'unsuccessful'
elif not statuses.difference(set(['complete', 'unsuccessful', 'cancelled'])):
LOGGER.info('Switched tender {} to {}'.format(tender.id, 'complete'),
extra=context_unpack(request, {'MESSAGE_ID': 'switched_tender_complete'}))
tender.status = 'complete'
else:
pending_complaints = any([
i.status in ['claim', 'answered', 'pending']
i.status in tender.block_complaint_status
for i in tender.complaints
])
pending_awards_complaints = any([
i.status in ['claim', 'answered', 'pending']
i.status in tender.block_complaint_status
for a in tender.awards
for i in a.complaints
])
Expand All @@ -480,11 +458,10 @@ def check_tender_status(request):
]
stand_still_end = max(stand_still_ends) if stand_still_ends else now
stand_still_time_expired = stand_still_end < now
active_awards = any([
a.status in ['active', 'pending']
for a in tender.awards
])
if not active_awards and not pending_complaints and not pending_awards_complaints and stand_still_time_expired:
last_award_status = tender.awards[-1].status if tender.awards else ''
if not pending_complaints and not pending_awards_complaints and stand_still_time_expired and last_award_status == 'unsuccessful':
LOGGER.info('Switched tender {} to {}'.format(tender.id, 'unsuccessful'),
extra=context_unpack(request, {'MESSAGE_ID': 'switched_tender_unsuccessful'}))
tender.status = 'unsuccessful'
if tender.contracts and tender.contracts[-1].status == 'active':
tender.status = 'complete'
Expand Down

0 comments on commit 934f857

Please sign in to comment.