def test_check_auction_protocol(self):
        def get_document(documentType, author):
            return {'documentType': documentType, 'author': author}

        document = get_document('auctionProtocol', 'auction_owner')
        award = munch.Munch({'documents': [document]})
        result = check_document_existence(award, 'auctionProtocol')
        self.assertEqual(result, True)

        document = get_document('auctionProtocol', 'not_auction_owner')
        award = munch.Munch({'documents': [document]})
        result = check_document_existence(award, 'auctionProtocol')
        self.assertEqual(result, False)

        award = munch.Munch({'documents': []})
        result = check_document_existence(award, 'auctionProtocol')
        self.assertEqual(result, False)

        document = get_document('not_auctionProtocol', 'auction_owner')
        award = munch.Munch({'documents': [document]})
        result = check_document_existence(award, 'auctionProtocol')
        self.assertEqual(result, False)
예제 #2
0
    def change_award(self, request, **kwargs):
        auction = request.validated['auction']
        award = request.context
        current_award_status = award.status
        server_id = kwargs['server_id']

        now = get_now()
        if current_award_status in ['unsuccessful', 'cancelled', 'active']:
            request.errors.add(
                'body',
                'data',
                'Can\'t update award in current ({}) status'.format(current_award_status)
            )
            request.errors.status = 403
            raise error_handler(request)

        apply_patch(request, save=False, src=request.context.serialize())
        new_award_status = award.status

        if current_award_status == 'pending.waiting' and new_award_status == 'cancelled':
            if request.authenticated_role == 'bid_owner':
                award.complaintPeriod.endDate = now
            else:
                request.errors.add(
                    'body',
                    'data',
                    'Only bid owner may cancel award in current ({}) status'.format(current_award_status)
                )
                request.errors.status = 403
                raise error_handler(request)

        elif current_award_status == 'pending.admission' and new_award_status == 'pending':
            if check_document_existence(award, 'admissionProtocol'):
                award.admissionPeriod.endDate = now
                award.signingPeriod = award.verificationPeriod = {'startDate': now}
            else:
                request.errors.add(
                    'body',
                    'data',
                    'Can\'t switch award status to (pending) before'
                    ' auction owner load admission protocol'
                )
                request.errors.status = 403
                raise error_handler(request)

        elif current_award_status == 'pending' and new_award_status == 'active':
            if check_document_existence(award, 'auctionProtocol'):
                award.verificationPeriod.endDate = now
            else:
                request.errors.add(
                    'body',
                    'data',
                    'Can\'t switch award status to (active) before'
                    ' auction owner load auction protocol'
                )
                request.errors.status = 403
                raise error_handler(request)

            award.complaintPeriod.endDate = now
            auction.contracts.append(type(auction).contracts.model_class({
                'awardID': award.id,
                'suppliers': award.suppliers,
                'value': award.value,
                'date': get_now(),
                'items': auction.items,
                'contractID': '{}-{}{}'.format(
                    auction.auctionID,
                    server_id,
                    len(auction.contracts) + 1
                ),
                'signingPeriod': award.signingPeriod,
            }))
            auction.status = 'active.awarded'
            auction.awardPeriod.endDate = now

        elif current_award_status != 'pending.waiting' and new_award_status == 'unsuccessful':
            if not (check_document_existence(award, 'rejectionProtocol') or
                    check_document_existence(award, 'act')):
                request.errors.add(
                    'body',
                    'data',
                    'Can\'t switch award status to (unsuccessful) before'
                    ' auction owner load reject protocol or act'
                )
                request.errors.status = 403
                raise error_handler(request)
            if current_award_status == 'pending.admission':
                award.admissionPeriod.endDate = now
            elif current_award_status == 'pending':
                award.verificationPeriod.endDate = now
            award.complaintPeriod.endDate = now
            request.content_configurator.back_to_awarding()

        elif current_award_status != new_award_status:
            request.errors.add(
                'body',
                'data',
                'Can\'t switch award ({0}) status to ({1}) status'.format(
                    current_award_status,
                    new_award_status
                )
            )
            request.errors.status = 403
            raise error_handler(request)
예제 #3
0
    def change_award(self, request, **kwargs):
        auction = request.validated['auction']
        award = request.context
        server_id = kwargs['server_id']

        current_award_status = award.status
        apply_patch(request, save=False, src=request.context.serialize())
        now = get_now()
        if current_award_status == 'pending.waiting' and award.status == 'cancelled':
            if request.authenticated_role == 'bid_owner':
                award.complaintPeriod.endDate = now
            else:
                request.errors.add(
                    'body', 'data',
                    'Only bid owner may cancel award in current ({}) status'.
                    format(current_award_status))
                request.errors.status = 403
                raise error_handler(request)
        elif current_award_status == 'pending.verification' and award.status == 'pending.payment':
            if check_document_existence(award, 'auctionProtocol'):
                award.verificationPeriod.endDate = now
            else:
                request.errors.add(
                    'body', 'data',
                    'Can\'t switch award status to (pending.payment) before auction owner load auction protocol'
                )
                request.errors.status = 403
                raise error_handler(request)
        elif current_award_status == 'pending.payment' and award.status == 'active':
            award.complaintPeriod.endDate = award.paymentPeriod.endDate = now
            auction.contracts.append(
                type(auction).contracts.model_class({
                    'awardID':
                    award.id,
                    'suppliers':
                    award.suppliers,
                    'value':
                    award.value,
                    'date':
                    now,
                    'items':
                    [i for i in auction.items if i.relatedLot == award.lotID],
                    'contractID':
                    '{}-{}{}'.format(auction.auctionID, server_id,
                                     len(auction.contracts) + 1)
                }))
            auction.status = 'active.awarded'
            auction.awardPeriod.endDate = now
        elif current_award_status != 'pending.waiting' and award.status == 'unsuccessful':
            if current_award_status == 'pending.verification':
                award.verificationPeriod.endDate = \
                    award.complaintPeriod.endDate = \
                    award.paymentPeriod.endDate = \
                    award.signingPeriod.endDate = \
                    now
            elif current_award_status == 'pending.payment':
                award.paymentPeriod.endDate = now
            elif current_award_status == 'active':
                award.signingPeriod.endDate = now
                auction.awardPeriod.endDate = None
                auction.status = 'active.qualification'
                for i in auction.contracts:
                    if i.awardID == award.id:
                        i.status = 'cancelled'
            award.complaintPeriod.endDate = now
            request.content_configurator.back_to_awarding()
        elif current_award_status != award.status:
            request.errors.add(
                'body', 'data',
                'Can\'t switch award ({}) status to ({}) status'.format(
                    current_award_status, award.status))
            request.errors.status = 403
            raise error_handler(request)
    def change_award(self, request, **kwargs):
        auction = request.validated['auction']
        award = request.context
        current_award_status = award.status
        server_id = kwargs['server_id']

        now = get_now()
        if current_award_status in ['unsuccessful', 'cancelled']:
            request.errors.add(
                'body', 'data',
                'Can\'t update award in current ({}) status'.format(
                    current_award_status))
            request.errors.status = 403
            raise error_handler(request)

        apply_patch(request, save=False, src=request.context.serialize())
        new_award_status = award.status

        if current_award_status == 'pending.waiting' and new_award_status == 'cancelled':
            if request.authenticated_role == 'bid_owner':
                award.complaintPeriod.endDate = now
            else:
                request.errors.add(
                    'body', 'data',
                    'Only bid owner may cancel award in current ({}) status'.
                    format(current_award_status))
                request.errors.status = 403
                raise error_handler(request)

        elif current_award_status == 'pending' and new_award_status == 'active':
            if check_document_existence(award, 'auctionProtocol'):
                award.verificationPeriod.endDate = now
            else:
                request.errors.add(
                    'body', 'data',
                    'Can\'t switch award status to (active) before'
                    ' auction owner load auction protocol')
                request.errors.status = 403
                raise error_handler(request)

            award.complaintPeriod.endDate = now
            auction.contracts.append(
                type(auction).contracts.model_class({
                    'awardID':
                    award.id,
                    'suppliers':
                    award.suppliers,
                    'value':
                    award.value,
                    'date':
                    get_now(),
                    'items':
                    auction.items,
                    'contractID':
                    '{}-{}{}'.format(auction.auctionID, server_id,
                                     len(auction.contracts) + 1),
                    'signingPeriod':
                    award.signingPeriod,
                }))
            auction.status = 'active.awarded'
            auction.awardPeriod.endDate = now
        elif current_award_status != 'pending.waiting' and new_award_status == 'unsuccessful':
            if current_award_status == 'pending':
                award.verificationPeriod.endDate = now
            elif current_award_status == 'active':
                contract = None
                for contract in auction.contracts:
                    if contract.awardID == award.id:
                        break
                if getattr(contract, 'dateSigned', False):
                    err_message = 'You cannot disqualify the bidder the contract for whom has already been downloaded.'
                    request.errors.add('body', 'data', err_message)
                    request.errors.status = 403
                    raise error_handler(request)
                award.signingPeriod.endDate = now
                auction.awardPeriod.endDate = None
                auction.status = 'active.qualification'
                for i in auction.contracts:
                    if i.awardID == award.id:
                        i.status = 'cancelled'
            award.complaintPeriod.endDate = now
            request.content_configurator.back_to_awarding()
        elif current_award_status != new_award_status:
            request.errors.add(
                'body', 'data',
                'Can\'t switch award ({0}) status to ({1}) status'.format(
                    current_award_status, new_award_status))
            request.errors.status = 403
            raise error_handler(request)