Exemple #1
0
def create_auction_auctionPeriod(self):
    data = self.initial_data.copy()
    # tenderPeriod = data.pop('tenderPeriod')
    # data['auctionPeriod'] = {'startDate': tenderPeriod['endDate']}
    response = self.app.post_json('/auctions', {'data': data})
    self.assertEqual(response.status, '201 Created')
    self.assertEqual(response.content_type, 'application/json')
    auction = response.json['data']
    self.assertIn('tenderPeriod', auction)
    self.assertIn('auctionPeriod', auction)
    self.assertNotIn('startDate', auction['auctionPeriod'])
    self.assertEqual(parse_date(data['auctionPeriod']['startDate']).date(),
                     parse_date(auction['auctionPeriod']['shouldStartAfter'], TZ).date())
    if SANDBOX_MODE:
        auction_startDate = parse_date(data['auctionPeriod']['startDate'], None)
        if not auction_startDate.tzinfo:
            auction_startDate = TZ.localize(auction_startDate)
        tender_endDate = parse_date(auction['tenderPeriod']['endDate'], None)
        if not tender_endDate.tzinfo:
            tender_endDate = TZ.localize(tender_endDate)
        self.assertLessEqual((auction_startDate - tender_endDate).total_seconds(), 70)
    else:
        self.assertEqual(parse_date(auction['tenderPeriod']['endDate']).date(),
                         parse_date(data['auctionPeriod']['startDate'], TZ).date() - timedelta(days=1))
        self.assertEqual(parse_date(auction['tenderPeriod']['endDate']).time(), time(20, 0))
Exemple #2
0
 def initialize(self):
     if not self.enquiryPeriod:
         self.enquiryPeriod = type(self).enquiryPeriod.model_class()
     if not self.tenderPeriod:
         self.tenderPeriod = type(self).tenderPeriod.model_class()
     now = get_now()
     start_date = TZ.localize(
         self.auctionPeriod.startDate.replace(tzinfo=None))
     self.tenderPeriod.startDate = self.enquiryPeriod.startDate = now
     pause_between_periods = start_date - (start_date.replace(
         hour=20, minute=0, second=0, microsecond=0) - timedelta(days=1))
     end_date = calculate_business_date(start_date, -pause_between_periods,
                                        self)
     self.enquiryPeriod.endDate = end_date
     self.tenderPeriod.endDate = self.enquiryPeriod.endDate
     if not self.rectificationPeriod:
         self.rectificationPeriod = generate_rectificationPeriod_tender_period_margin(
             self)
     self.rectificationPeriod.startDate = now
     self.auctionPeriod.startDate = None
     self.auctionPeriod.endDate = None
     self.date = now
     if self.lots:
         for lot in self.lots:
             lot.date = now
 def initialize(self):
     if not self.enquiryPeriod:
         self.enquiryPeriod = type(self).enquiryPeriod.model_class()
     if not self.tenderPeriod:
         self.tenderPeriod = type(self).tenderPeriod.model_class()
     now = get_now()
     start_date = TZ.localize(
         self.auctionPeriod.startDate.replace(
             tzinfo=None))
     self.auctionPeriod.startDate = None
     self.auctionPeriod.endDate = None
     self.tenderPeriod.startDate = self.enquiryPeriod.startDate = now
     pause_between_periods = start_date - (
         start_date.replace(hour=20, minute=0, second=0, microsecond=0) -
         # set period end at 19:30-20:30 to reduce system load
         timedelta(days=1, minutes=randint(-30, 30))
     )
     end_date = calculate_business_date(
         start_date, -pause_between_periods, self)
     self.enquiryPeriod.endDate = end_date
     self.tenderPeriod.endDate = self.enquiryPeriod.endDate
     self.date = now
     if self.lots:
         for lot in self.lots:
             lot.date = now
    def create_auction(self, request):
        self._validate(request, self.create_validation)

        auction = request.validated['auction']

        if not auction.enquiryPeriod:
            auction.enquiryPeriod = type(auction).enquiryPeriod.model_class()
        if not auction.tenderPeriod:
            auction.tenderPeriod = type(auction).tenderPeriod.model_class()

        now = get_now()
        start_date = TZ.localize(auction.auctionPeriod.startDate.replace(tzinfo=None))
        auction.auctionPeriod.startDate = None
        auction.auctionPeriod.endDate = None

        auction.tenderPeriod.startDate = auction.enquiryPeriod.startDate = now

        # Specific logic to make enquiryPeriod.endDate be one day before auctionPeriod.startDate and be set 20 hour
        pause_between_periods = start_date - (start_date.replace(hour=20, minute=0, second=0, microsecond=0) - timedelta(days=1))
        auction.enquiryPeriod.endDate = calculate_business_date(start_date, -pause_between_periods, auction).astimezone(TZ)

        # Specific logic to make tenderPeriod.endDate be from enquiryPeriod.endDate until end of auction
        time_before_tendering_end = (start_date.replace(hour=9, minute=30, second=0, microsecond=0) + DUTCH_PERIOD) - auction.enquiryPeriod.endDate
        auction.tenderPeriod.endDate = calculate_business_date(auction.enquiryPeriod.endDate, time_before_tendering_end, auction)

        if SANDBOX_MODE and auction.submissionMethodDetails and 'quick' in auction.submissionMethodDetails:
            auction.tenderPeriod.endDate = (auction.enquiryPeriod.endDate + QUICK_DUTCH_PERIOD).astimezone(TZ)

        auction.auctionPeriod.startDate = None
        auction.auctionPeriod.endDate = None
        auction.date = now
        if not auction.auctionParameters:
            auction.auctionParameters = type(auction).auctionParameters.model_class()
 def initialize(self):
     if not self.enquiryPeriod:
         self.enquiryPeriod = type(self).enquiryPeriod.model_class()
     if not self.tenderPeriod:
         self.tenderPeriod = type(self).tenderPeriod.model_class()
     now = get_now()
     start_date = TZ.localize(
         self.auctionPeriod.startDate.replace(tzinfo=None))
     self.auctionPeriod.startDate = None
     self.auctionPeriod.endDate = None
     self.tenderPeriod.startDate = self.enquiryPeriod.startDate = now
     pause_between_periods = start_date - (start_date.replace(
         hour=20, minute=0, second=0, microsecond=0) - timedelta(days=1))
     self.enquiryPeriod.endDate = calculate_business_date(
         start_date, -pause_between_periods, self).astimezone(TZ)
     time_before_tendering_end = (
         start_date.replace(hour=9, minute=30, second=0, microsecond=0) +
         DUTCH_PERIOD) - self.enquiryPeriod.endDate
     self.tenderPeriod.endDate = calculate_business_date(
         self.enquiryPeriod.endDate, time_before_tendering_end, self)
     if SANDBOX_MODE and self.submissionMethodDetails and 'quick' in self.submissionMethodDetails:
         self.tenderPeriod.endDate = (self.enquiryPeriod.endDate +
                                      QUICK_DUTCH_PERIOD).astimezone(TZ)
     self.auctionPeriod.startDate = None
     self.auctionPeriod.endDate = None
     self.date = now
     self.documents.append(
         type(self).documents.model_class(DGF_PLATFORM_LEGAL_DETAILS))
     if not self.auctionParameters:
         self.auctionParameters = type(self).auctionParameters.model_class()
 def validate_rectificationPeriod(self, data, period):
     if not (period and period.startDate) or not period.endDate:
         return
     if period.endDate > TZ.localize(
             calculate_business_date(data['tenderPeriod']['endDate'],
                                     -MINIMAL_PERIOD_FROM_RECTIFICATION_END,
                                     data).replace(tzinfo=None)):
         raise ValidationError(
             u"rectificationPeriod.endDate should come at least 5 working days earlier than tenderPeriod.endDate"
         )
    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 initialize(self):
     if not self.enquiryPeriod:
         self.enquiryPeriod = type(self).enquiryPeriod.model_class()
     if not self.tenderPeriod:
         self.tenderPeriod = type(self).tenderPeriod.model_class()
     now = get_now()
     start_date = TZ.localize(self.auctionPeriod.startDate.replace(tzinfo=None))
     self.auctionPeriod.startDate = None
     self.auctionPeriod.endDate = None
     self.tenderPeriod.startDate = self.enquiryPeriod.startDate = now
     pause_between_periods = start_date - (start_date.replace(hour=20, minute=0, second=0, microsecond=0) - timedelta(days=1))
     end_date = calculate_business_date(start_date, -pause_between_periods, self)
     self.enquiryPeriod.endDate = end_date
     self.tenderPeriod.endDate = self.enquiryPeriod.endDate
     self.date = now
     if self.lots:
         for lot in self.lots:
             lot.date = now
     self.documents.append(type(self).documents.model_class(DGF_PLATFORM_LEGAL_DETAILS))
Exemple #9
0
    def create_auction(self, request):
        self._validate(request, self.create_validation)

        auction = request.validated['auction']

        for i in request.validated['json_data'].get('documents', []):
            document = type(auction).documents.model_class(i)
            document.__parent__ = auction
            auction.documents.append(document)

        if not auction.enquiryPeriod:
            auction.enquiryPeriod = type(auction).enquiryPeriod.model_class()
        if not auction.tenderPeriod:
            auction.tenderPeriod = type(auction).tenderPeriod.model_class()
        now = get_now()
        start_date = TZ.localize(
            auction.auctionPeriod.startDate.replace(tzinfo=None))
        auction.auctionPeriod.startDate = None
        auction.auctionPeriod.endDate = None
        auction.tenderPeriod.startDate = auction.enquiryPeriod.startDate = now
        pause_between_periods = start_date - (start_date.replace(
            hour=20, minute=0, second=0, microsecond=0) - timedelta(days=1))
        auction.enquiryPeriod.endDate = calculate_business_date(
            start_date, -pause_between_periods, auction).astimezone(TZ)
        time_before_tendering_end = (
            start_date.replace(hour=9, minute=30, second=0, microsecond=0) +
            DUTCH_PERIOD) - auction.enquiryPeriod.endDate
        auction.tenderPeriod.endDate = calculate_business_date(
            auction.enquiryPeriod.endDate, time_before_tendering_end, auction)
        if SANDBOX_MODE and auction.submissionMethodDetails and 'quick' in auction.submissionMethodDetails:
            auction.tenderPeriod.endDate = (auction.enquiryPeriod.endDate +
                                            QUICK_DUTCH_PERIOD).astimezone(TZ)
        auction.auctionPeriod.startDate = None
        auction.auctionPeriod.endDate = None
        auction.date = now
        if not auction.auctionParameters:
            auction.auctionParameters = type(
                auction).auctionParameters.model_class()