Exemple #1
0
def create_awards(request):
    """
        Function create NUMBER_OF_BIDS_TO_BE_QUALIFIED awards objects
        First award always in pending.verification status
        others in pending.waiting status
        In case that only one bid was applied, award object
        in pending.admission status will be created for that bid
    """
    auction = request.validated['auction']
    auction.status = 'active.qualification'
    now = get_now()
    auction.awardPeriod = type(auction).awardPeriod({'startDate': now})
    awarding_type = request.content_configurator.awarding_type
    valid_bids = [bid for bid in auction.bids if bid['value'] is not None]
    if len(valid_bids) == 1:
        bid = valid_bids[0].serialize()
        award = make_award(request,
                           auction,
                           bid,
                           'pending.admission',
                           now,
                           parent=True)
        if bid['status'] == 'invalid':
            set_award_status_unsuccessful(award, now)
        if award.status == 'pending.admission':
            award.admissionPeriod = {
                'startDate':
                now,
                'endDate':
                calculate_business_date(now, VERIFY_ADMISSION_PROTOCOL_TIME,
                                        auction, True,
                                        AWARDING_PERIODS_END_DATE_HOUR)
            }
            add_award_route_url(request, auction, award, awarding_type)
        auction.awards.append(award)
    else:
        bids = chef(valid_bids, auction.features or [], [], True)
        bids_to_qualify = get_bids_to_qualify(bids)
        for bid, status in izip_longest(bids[:bids_to_qualify], ['pending'],
                                        fillvalue='pending.waiting'):
            bid = bid.serialize()
            award = make_award(request, auction, bid, status, now, parent=True)
            if bid['status'] == 'invalid':
                set_award_status_unsuccessful(award, now)
            if award.status == 'pending':
                award.signingPeriod = award.verificationPeriod = {
                    'startDate': now
                }
                add_award_route_url(request, auction, award, awarding_type)
            auction.awards.append(award)
def create_awards(request):
    """
        Function create NUMBER_OF_BIDS_TO_BE_QUALIFIED awards objects
        First award always in pending.verification status
        others in pending.waiting status
    """
    auction = request.validated['auction']
    auction.status = 'active.qualification'
    now = get_now()
    auction.awardPeriod = type(auction).awardPeriod({'startDate': now})
    awarding_type = request.content_configurator.awarding_type
    valid_bids = [bid for bid in auction.bids if bid['value'] is not None]
    bids = chef(valid_bids, auction.features or [], [], True)
    bids_to_qualify = get_bids_to_qualify(bids)
    for i in xrange(0, bids_to_qualify):
        status = 'pending.waiting'
        if i == 0:
            status = 'pending.verification'
        bid = bids[i].serialize()
        award = make_award(request, auction, bid, status, now, parent=True)
        if bid['status'] == 'invalid':
            set_award_status_unsuccessful(award, now)
        if award.status == 'pending.verification':
            award.signingPeriod = award.paymentPeriod = award.verificationPeriod = {
                'startDate': now
            }
            add_award_route_url(request, auction, award, awarding_type)
        auction.awards.append(award)
def create_awards(request):
    """
        Function create NUMBER_OF_BIDS_TO_BE_QUALIFIED awards objects
        First award always in pending.verification status
        others in pending.waiting status
    """
    auction = request.validated['auction']
    auction.status = 'active.qualification'
    now = get_now()
    auction.awardPeriod = type(auction).awardPeriod({'startDate': now})
    awarding_type = request.content_configurator.awarding_type
    bids = chef(auction.bids, auction.features or [], [], True)
    # minNumberOfQualifiedBids == 1
    bids_to_qualify = get_bids_to_qualify(bids)
    for bid, status in izip_longest(bids[:bids_to_qualify],
                                    ['pending.verification'],
                                    fillvalue='pending.waiting'):
        bid = bid.serialize()
        award = make_award(request, auction, bid, status, now, parent=True)
        if bid['status'] == 'invalid':
            set_award_status_unsuccessful(award, now)
        if award.status == 'pending.verification':
            award.verificationPeriod = award.paymentPeriod = award.signingPeriod = {
                'startDate': now
            }
            add_award_route_url(request, auction, award, awarding_type)
        auction.awards.append(award)
Exemple #4
0
    def _start_awarding(self):
        """
            Function create NUMBER_OF_BIDS_TO_BE_QUALIFIED awards objects
            First award always in pending.verification status
            others in pending.waiting status
            In case that only one bid was applied, award object
            in pending.admission status will be created for that bid
        """

        auction = self.context
        auction.status = 'active.qualification'
        now = get_now()

        auction.awardPeriod = type(auction).awardPeriod({'startDate': now})
        awarding_type = self.awarding_type
        valid_bids = [bid for bid in auction.bids if self.is_bid_valid(bid)]

        award_status = 'pending.admission' if len(
            valid_bids
        ) == 1 and self.pending_admission_for_one_bid else 'pending'

        bids = chef(valid_bids, auction.features or [], [], True)
        bids_to_qualify = self.get_bids_to_qualify(bids)
        for bid, status in izip_longest(bids[:bids_to_qualify], [award_status],
                                        fillvalue='pending.waiting'):
            bid = bid.serialize()
            award = make_award(self.request,
                               auction,
                               bid,
                               status,
                               now,
                               parent=True)

            if bid['status'] == 'invalid':
                set_award_status_unsuccessful(award, now)
            if award.status == 'pending':
                award.verificationPeriod = self.verificationPeriod()
                award.signingPeriod = self.signingPeriod()
                add_award_route_url(self.request, auction, award,
                                    awarding_type)
            if award.status == 'pending.admission':
                award.admissionPeriod = {
                    'startDate':
                    now,
                    'endDate':
                    calculate_business_date(start=now,
                                            context=auction,
                                            **award.ADMISSION_PERIOD_PARAMS)
                }
                add_award_route_url(self.request, auction, award,
                                    awarding_type)
            auction.awards.append(award)
        return True
Exemple #5
0
def add_next_award(request):
    auction = request.validated['auction']
    awarding_type = request.content_configurator.awarding_type
    now = get_now()
    if not auction.awardPeriod:
        auction.awardPeriod = type(auction).awardPeriod({})
    if not auction.awardPeriod.startDate:
        auction.awardPeriod.startDate = now
    if auction.lots:
        statuses = set()
        for lot in auction.lots:
            if lot.status != 'active':
                continue
            lot_awards = [i for i in auction.awards if i.lotID == lot.id]
            if lot_awards and lot_awards[-1].status in ['pending', 'active']:
                statuses.add(
                    lot_awards[-1].status if lot_awards else 'unsuccessful')
                continue
            lot_items = [i.id for i in auction.items if i.relatedLot == lot.id]
            features = [
                i for i in (auction.features or [])
                if i.featureOf == 'tenderer'
                or i.featureOf == 'lot' and i.relatedItem == lot.id
                or i.featureOf == 'item' and i.relatedItem in lot_items
            ]
            codes = [i.code for i in features]
            bids = [{
                'id':
                bid.id,
                'value': [i for i in bid.lotValues
                          if lot.id == i.relatedLot][0].value,
                'tenderers':
                bid.tenderers,
                'parameters': [i for i in bid.parameters if i.code in codes],
                'date': [i for i in bid.lotValues
                         if lot.id == i.relatedLot][0].date
            } for bid in auction.bids
                    if lot.id in [i.relatedLot for i in bid.lotValues]]
            if not bids:
                lot.status = 'unsuccessful'
                statuses.add('unsuccessful')
                continue
            unsuccessful_awards = [
                i.bid_id for i in lot_awards if i.status == 'unsuccessful'
            ]
            bids = chef(bids, features, unsuccessful_awards, True)
            if bids:
                bid = bids[0]
                award = make_award(request,
                                   auction,
                                   bid,
                                   'pending',
                                   now,
                                   lot_id=lot.id,
                                   parent=None)
                auction.awards.append(award)
                add_award_route_url(request, auction, award, awarding_type)
                statuses.add('pending')
            else:
                statuses.add('unsuccessful')
        if statuses.difference(set(['unsuccessful', 'active'])):
            auction.awardPeriod.endDate = None
            auction.status = 'active.qualification'
        else:
            auction.awardPeriod.endDate = now
            auction.status = 'active.awarded'
    else:
        if not auction.awards or auction.awards[-1].status not in [
                'pending', 'active'
        ]:
            unsuccessful_awards = [
                i.bid_id for i in auction.awards if i.status == 'unsuccessful'
            ]
            bids = chef(auction.bids, auction.features or [],
                        unsuccessful_awards, True)
            if bids:
                bid = bids[0].serialize()
                award = make_award(request,
                                   auction,
                                   bid,
                                   'pending',
                                   now,
                                   parent=None)
                auction.awards.append(award)
                add_award_route_url(request, auction, award, awarding_type)
        if auction.awards[-1].status == 'pending':
            auction.awardPeriod.endDate = None
            auction.status = 'active.qualification'
        else:
            auction.awardPeriod.endDate = now
            auction.status = 'active.awarded'