Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/a261876877005284_create_contract…
Browse files Browse the repository at this point in the history
…s_by_chronograph'
  • Loading branch information
kroman0 committed Feb 6, 2017
2 parents fcc4a71 + 151ad97 commit 2f4288a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}

setup(name='openprocurement.api',
version='2.3.43',
version='2.3.46',
description='openprocurement.api',
long_description=README,
classifiers=[
Expand Down
2 changes: 2 additions & 0 deletions src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,8 @@ def next_check(self):
elif complaint.status == 'answered' and complaint.dateAnswered:
checks.append(calculate_business_date(complaint.dateAnswered, COMPLAINT_STAND_STILL_TIME, self))
for award in self.awards:
if award.status == 'active' and not any([i.awardID == award.id for i in self.contracts]):
checks.append(award.date)
for complaint in award.complaints:
if complaint.status == 'claim' and complaint.dateSubmitted:
checks.append(calculate_business_date(complaint.dateSubmitted, COMPLAINT_STAND_STILL_TIME, self))
Expand Down
54 changes: 54 additions & 0 deletions src/openprocurement/api/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,60 @@ def test_first_bid_tender(self):
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can't update document in current (complete) tender status")

def test_lost_contract_for_active_award(self):
self.app.authorization = ('Basic', ('broker', ''))
# create tender
response = self.app.post_json('/tenders',
{"data": test_tender_data})
tender_id = self.tender_id = response.json['data']['id']
owner_token = response.json['access']['token']
# switch to active.tendering
self.set_status('active.tendering')
# create bid
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.post_json('/tenders/{}/bids'.format(tender_id),
{'data': {'tenderers': [test_organization], "value": {"amount": 500}}})
# switch to active.qualification
self.set_status('active.auction', {"auctionPeriod": {"startDate": None}, 'status': 'active.tendering'})
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/tenders/{}'.format(tender_id), {"data": {"id": tender_id}})
# get awards
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.get('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token))
# get pending award
award_id = [i['id'] for i in response.json['data'] if i['status'] == 'pending'][0]
# set award as active
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, owner_token),
{"data": {"status": "active"}})
# lost contract
tender = self.db.get(tender_id)
tender['contracts'] = None
self.db.save(tender)
# check tender
response = self.app.get('/tenders/{}'.format(tender_id))
self.assertEqual(response.json['data']['status'], 'active.awarded')
self.assertNotIn('contracts', response.json['data'])
self.assertIn('next_check', response.json['data'])
# create lost contract
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/tenders/{}'.format(tender_id), {"data": {"id": tender_id}})
self.assertEqual(response.json['data']['status'], 'active.awarded')
self.assertIn('contracts', response.json['data'])
self.assertNotIn('next_check', response.json['data'])
contract_id = response.json['data']['contracts'][-1]['id']
# time travel
tender = self.db.get(tender_id)
for i in tender.get('awards', []):
i['complaintPeriod']['endDate'] = i['complaintPeriod']['startDate']
self.db.save(tender)
# sign contract
self.app.authorization = ('Basic', ('broker', ''))
self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(tender_id, contract_id, owner_token), {"data": {"status": "active"}})
# check status
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.get('/tenders/{}'.format(tender_id))
self.assertEqual(response.json['data']['status'], 'complete')


def suite():
suite = unittest.TestSuite()
Expand Down
9 changes: 9 additions & 0 deletions src/openprocurement/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,15 @@ def check_status(request):
for complaint in tender.complaints:
check_complaint_status(request, complaint, now)
for award in tender.awards:
if award.status == 'active' and not any([i.awardID == award.id for i in tender.contracts]):
tender.contracts.append(type(tender).contracts.model_class({
'awardID': award.id,
'suppliers': award.suppliers,
'value': award.value,
'date': now,
'items': [i for i in tender.items if i.relatedLot == award.lotID ],
'contractID': '{}-{}{}'.format(tender.tenderID, request.registry.server_id, len(tender.contracts) + 1) }))
add_next_award(request)
for complaint in award.complaints:
check_complaint_status(request, complaint, now)
if tender.status == 'active.enquiries' and not tender.tenderPeriod.startDate and tender.enquiryPeriod.endDate.astimezone(TZ) <= now:
Expand Down

0 comments on commit 2f4288a

Please sign in to comment.