Skip to content

Commit

Permalink
Merge branch 'a139580578997856_shouldStartAfter_rounding'
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Jun 14, 2016
2 parents 86c259e + bf228fc commit 74bb2eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
20 changes: 15 additions & 5 deletions src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import os
from couchdb_schematics.document import SchematicsDocument
from datetime import datetime, timedelta
from datetime import datetime, timedelta, time
from iso8601 import parse_date, ParseError
from pytz import timezone
from pyramid.security import Allow
Expand Down Expand Up @@ -229,6 +229,14 @@ def calc_auction_end_time(bids, start):
return start + bids * BIDDER_TIME + SERVICE_TIME + AUCTION_STAND_STILL_TIME


def rounding_shouldStartAfter(start_after, tender, use_from=datetime(2016, 6, 1, tzinfo=TZ)):
if (tender.enquiryPeriod and tender.enquiryPeriod.startDate or get_now()) > use_from and not (SANDBOX_MODE and tender.submissionMethodDetails and u'quick' in tender.submissionMethodDetails):
midnigth = datetime.combine(start_after.date(), time(0, tzinfo=start_after.tzinfo))
if start_after > midnigth:
start_after = midnigth + timedelta(1)
return start_after


class TenderAuctionPeriod(Period):
"""The auction period."""

Expand All @@ -240,9 +248,10 @@ def shouldStartAfter(self):
if tender.lots or tender.status not in ['active.tendering', 'active.auction']:
return
if self.startDate and get_now() > calc_auction_end_time(tender.numberOfBids, self.startDate):
return calc_auction_end_time(tender.numberOfBids, self.startDate).isoformat()
start_after = calc_auction_end_time(tender.numberOfBids, self.startDate)
else:
return tender.tenderPeriod.endDate.isoformat()
start_after = tender.tenderPeriod.endDate
return rounding_shouldStartAfter(start_after, tender).isoformat()


class LotAuctionPeriod(Period):
Expand All @@ -259,9 +268,10 @@ def shouldStartAfter(self):
if tender.status == 'active.auction' and lot.numberOfBids < 2:
return
if self.startDate and get_now() > calc_auction_end_time(lot.numberOfBids, self.startDate):
return calc_auction_end_time(lot.numberOfBids, self.startDate).isoformat()
start_after = calc_auction_end_time(tender.numberOfBids, self.startDate)
else:
return tender.tenderPeriod.endDate.isoformat()
start_after = tender.tenderPeriod.endDate
return rounding_shouldStartAfter(start_after, tender).isoformat()


class PeriodEndRequired(Period):
Expand Down
19 changes: 10 additions & 9 deletions src/openprocurement/api/tests/chronograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def test_set_auction_period(self):
item = response.json['data']
self.assertIn('auctionPeriod', item)
self.assertIn('shouldStartAfter', item['auctionPeriod'])
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertIn('T00:00:00+', item['auctionPeriod']['shouldStartAfter'])
self.assertEqual(response.json['data']['next_check'], response.json['data']['tenderPeriod']['endDate'])

if self.initial_lots:
Expand Down Expand Up @@ -140,7 +141,7 @@ def test_reset_auction_period(self):
item = response.json['data']
self.assertIn('auctionPeriod', item)
self.assertIn('shouldStartAfter', item['auctionPeriod'])
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertEqual(response.json['data']['next_check'], response.json['data']['tenderPeriod']['endDate'])

if self.initial_lots:
Expand All @@ -150,15 +151,15 @@ def test_reset_auction_period(self):
response = self.app.patch_json('/tenders/{}'.format(self.tender_id), {'data': {"auctionPeriod": {"startDate": "9999-01-01T00:00:00"}}})
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertIn('9999-01-01T00:00:00', item['auctionPeriod']['startDate'])

self.set_status('active.auction', {'status': 'active.tendering'})
response = self.app.patch_json('/tenders/{}'.format(self.tender_id), {'data': {'id': self.tender_id}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
item = response.json['data']["lots"][0] if self.initial_lots else response.json['data']
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])

if self.initial_lots:
response = self.app.patch_json('/tenders/{}'.format(self.tender_id), {'data': {"lots": [{"auctionPeriod": {"startDate": "9999-01-01T00:00:00"}}]}})
Expand All @@ -168,7 +169,7 @@ def test_reset_auction_period(self):
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertIn('9999-01-01T00:00:00', item['auctionPeriod']['startDate'])
self.assertIn('9999-01-01T00:00:00', response.json['data']['next_check'])

Expand All @@ -184,7 +185,7 @@ def test_reset_auction_period(self):
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
item = response.json['data']["lots"][0] if self.initial_lots else response.json['data']
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreater(response.json['data']['next_check'], item['auctionPeriod']['startDate'])
self.assertEqual(response.json['data']['next_check'], self.db.get(self.tender_id)['next_check'])

Expand All @@ -196,7 +197,7 @@ def test_reset_auction_period(self):
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertNotIn('9999-01-01T00:00:00', item['auctionPeriod']['startDate'])
self.assertGreater(response.json['data']['next_check'], response.json['data']['tenderPeriod']['endDate'])

Expand All @@ -214,7 +215,7 @@ def test_reset_auction_period(self):
item = response.json['data']["lots"][0]
else:
item = response.json['data']
self.assertGreater(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertNotIn('next_check', response.json['data'])
self.assertNotIn('next_check', self.db.get(self.tender_id))
shouldStartAfter = item['auctionPeriod']['shouldStartAfter']
Expand All @@ -235,7 +236,7 @@ def test_reset_auction_period(self):
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertIn('9999-01-01T00:00:00', item['auctionPeriod']['startDate'])
self.assertIn('9999-01-01T00:00:00', response.json['data']['next_check'])

Expand Down

0 comments on commit 74bb2eb

Please sign in to comment.