def migrate_pendingPayment_active(self):
    auction = self.db.get(self.auction_id)

    pending_payment_award = award_fixture(auction, 'pending.payment', 0)
    pending_waiting_award = award_fixture(auction, 'pending.waiting', 1)

    auction['awards'] = [pending_waiting_award, pending_payment_award]
    auction.update(auction)
    self.db.save(auction)
    self.migrate_data(self.app.app.registry)

    response = self.app.get('/auctions/{}'.format(self.auction_id))
    auction = response.json['data']
    self.assertEqual(auction['status'], u'active.awarded')
    self.assertEqual(auction['awards'][1]['status'], u'active')
    self.assertEqual(auction['awards'][0]['status'], u'pending.waiting')

    response = self.app.get('/auctions/{}/contracts'.format(self.auction_id))
    contracts = response.json['data']
    self.assertEqual(len(contracts), 1)
    self.assertEqual(contracts[0]['status'], 'pending')
    signing_period_end_date = set_specific_hour(
        parse_datetime(pending_payment_award['signingPeriod']['endDate']),
        CONTRACT_SIGNING_PERIOD_END_DATE_HOUR)
    pending_payment_award['signingPeriod'][
        'endDate'] = signing_period_end_date.isoformat()
    self.assertEqual(contracts[0]['signingPeriod'],
                     pending_payment_award['signingPeriod'])
    def create_auction(self, request):
        auction = request.validated['auction']
        now = get_now()
        start_date = TZ.localize(
            auction.auctionPeriod.startDate.replace(tzinfo=None))
        pause_between_periods = start_date - (
            set_specific_hour(start_date, hour=20) - timedelta(days=1))
        end_date = calculate_business_date(start_date, -pause_between_periods,
                                           auction)
        if auction.tenderPeriod and auction.tenderPeriod.endDate:
            three_workingDays_before_startDate = calculate_business_date(
                start_date,
                -timedelta(days=3),
                auction,
                working_days=True,
                specific_hour=20)
            if auction.tenderPeriod.endDate.date(
            ) != three_workingDays_before_startDate.date():
                request.errors.add(
                    'body', 'data',
                    'The only possible value for tenderPeriod.endDate is {}'.
                    format(three_workingDays_before_startDate))
                request.errors.status = 422
                return
            else:
                auction.tenderPeriod.endDate = three_workingDays_before_startDate
        else:
            auction.tenderPeriod = type(auction).tenderPeriod.model_class()
            auction.tenderPeriod.endDate = end_date
        if not auction.enquiryPeriod:
            auction.enquiryPeriod = type(auction).enquiryPeriod.model_class()
        auction.enquiryPeriod.endDate = end_date
        if not auction.rectificationPeriod:
            auction.rectificationPeriod = generate_rectificationPeriod_tender_period_margin(
                auction)
        auction.tenderPeriod.startDate = auction.enquiryPeriod.startDate = auction.rectificationPeriod.startDate = auction.date = now
        auction.auctionPeriod.startDate = None
        auction.auctionPeriod.endDate = None
        if auction.lots:
            for lot in auction.lots:
                lot.date = now

        mandatory_additional_classificator = type(
            auction).items.model_class.additionalClassifications.model_class(
                MANDATORY_ADDITIONAL_CLASSIFICATOR)
        for item in auction['items']:
            for additionalClassification in item['additionalClassifications']:
                if (additionalClassification['scheme'] == u'CPVS'
                        and additionalClassification['id'] == u'PA01-7'):
                    break
            else:
                item['additionalClassifications'].append(
                    mandatory_additional_classificator)
def migrate_contract_pending(self):
    self.set_status('active.awarded')
    auction = self.db.get(self.auction_id)
    now = get_now()

    active_award = award_fixture(auction, 'active', 0)
    pending_waiting_award = award_fixture(auction, 'pending.waiting', 1)

    auction['awards'] = [active_award, pending_waiting_award]

    auction['contracts'] = [{
        'awardID': active_award['id'],
        'suppliers': active_award['suppliers'],
        'value': active_award['value'],
        'date': now.isoformat(),
        'items': auction['items'],
        'contractID': '{}-11'.format(auction['auctionID']),
        'status': 'pending',
        'signingPeriod': active_award['signingPeriod'],
    }]

    auction.update(auction)
    self.db.save(auction)
    self.migrate_data(self.app.app.registry)

    response = self.app.get('/auctions/{}'.format(self.auction_id))
    auction = response.json['data']
    self.assertEqual(auction['status'], u'active.awarded')
    self.assertEqual(auction['awards'][0]['status'], u'active')
    self.assertEqual(auction['awards'][1]['status'], u'pending.waiting')

    response = self.app.get('/auctions/{}/contracts'.format(self.auction_id))
    contracts = response.json['data']
    self.assertEqual(len(contracts), 1)
    self.assertEqual(contracts[0]['status'], 'pending')
    signing_period_end_date = set_specific_hour(
        parse_datetime(active_award['signingPeriod']['endDate']),
        CONTRACT_SIGNING_PERIOD_END_DATE_HOUR)
    active_award['signingPeriod'][
        'endDate'] = signing_period_end_date.isoformat()
    self.assertEqual(contracts[0]['signingPeriod'],
                     active_award['signingPeriod'])
def migrate_contract_cancelled(self):
    auction = self.db.get(self.auction_id)
    now = get_now()

    pending_verification_award = award_fixture(auction, 'pending.verification',
                                               0)
    unsuccessful_award = award_fixture(auction, 'unsuccessful', 1)

    auction['awards'] = [unsuccessful_award, pending_verification_award]

    auction['contracts'] = [{
        'awardID': unsuccessful_award['id'],
        'suppliers': unsuccessful_award['suppliers'],
        'value': unsuccessful_award['value'],
        'date': now.isoformat(),
        'items': auction['items'],
        'contractID': '{}-11'.format(auction['auctionID']),
        'status': 'cancelled'
    }]

    auction.update(auction)
    self.db.save(auction)
    self.migrate_data(self.app.app.registry)

    response = self.app.get('/auctions/{}'.format(self.auction_id))
    auction = response.json['data']
    self.assertEqual(auction['status'], u'active.qualification')
    self.assertEqual(auction['awards'][1]['status'], u'pending')

    response = self.app.get('/auctions/{}/contracts'.format(self.auction_id))
    contracts = response.json['data']
    self.assertEqual(len(contracts), 1)
    self.assertEqual(contracts[0]['status'], 'cancelled')
    signing_period_end_date = set_specific_hour(
        parse_datetime(unsuccessful_award['signingPeriod']['endDate']),
        CONTRACT_SIGNING_PERIOD_END_DATE_HOUR)
    unsuccessful_award['signingPeriod'][
        'endDate'] = signing_period_end_date.isoformat()
    self.assertEqual(contracts[0]['signingPeriod'],
                     unsuccessful_award['signingPeriod'])
Пример #5
0
def migrate_awarding2_to_awarding3(auction, server_id, procurementMethodTypes):
    """Migrate util from awarding v2 to awarding v3

       1. Rename pending.verification to pending.
       2. Remove pending.payment status with contract creation
       3. Adding signingPeriod to contract from award object
    """
    changed = False
    if auction['procurementMethodType'] not in procurementMethodTypes\
                or auction['status'] not in ['active.qualification', 'active.awarded'] \
                or 'awards' not in auction:
        return changed
    now = get_now().isoformat()

    for award in auction['awards']:
        if award['status'] == 'pending.verification':
            # Rename pending.verification to pending status
            award['status'] = 'pending'
            changed = True
        elif award['status'] == 'pending.payment':
            # Remove pending.payment status
            award['status'] = 'active'
            auction['status'] = 'active.awarded'
            # Create contract for award in pending.payment
            contract = {
                'id':
                uuid4().hex,
                'awardID':
                award['id'],
                'suppliers':
                award['suppliers'],
                'value':
                award['value'],
                'date':
                now,
                'items':
                auction['items'],
                'contractID':
                '{}-{}{}'.format(auction['auctionID'], server_id,
                                 len(auction.get('contracts', [])) + 1),
                'signingPeriod':
                award['signingPeriod']
            }
            contracts = auction.get('contracts', [])
            contracts.append(contract)
            auction['contracts'] = contracts
            changed = True
        # Migrate signingPeriod from Award to Contract
        for contract in auction.get('contracts', ''):
            award = filter(lambda x: x['id'] == contract['awardID'],
                           auction['awards'])[0]
            if not contract.get('signingPeriod', False):
                contract.update({'signingPeriod': award['signingPeriod']})
                changed = True
            # Set specific hour to signingPeriod.endDate of Contract
            if contract['signingPeriod'].get('endDate'):
                contract_signing_period_end_date = parse_datetime(
                    contract['signingPeriod']['endDate'])
                if contract_signing_period_end_date.time() != time(
                        CONTRACT_SIGNING_PERIOD_END_DATE_HOUR):
                    contract['signingPeriod']['endDate'] = set_specific_hour(
                        contract_signing_period_end_date,
                        CONTRACT_SIGNING_PERIOD_END_DATE_HOUR).isoformat()
                    changed = True
    return changed