def complaintPeriod(self):
     if self.tenderPeriod.startDate < COMPLAINT_OLD_SUBMIT_TIME_BEFORE:
         return Period(dict(startDate=self.tenderPeriod.startDate,
                            endDate=calculate_business_date(self.tenderPeriod.endDate, -COMPLAINT_OLD_SUBMIT_TIME, self)))
     else:
         normalized_end = calculate_normalized_date(self.tenderPeriod.endDate, self)
         return Period(dict(startDate=self.tenderPeriod.startDate,
                            endDate=calculate_business_date(normalized_end, -COMPLAINT_SUBMIT_TIME, self, True)))
 def tender_enquiryPeriod(self):
     endDate = calculate_business_date(self.tenderPeriod.endDate,
                                       -ENQUIRY_PERIOD_TIME, self, True)
     return EnquiryPeriod(
         dict(startDate=self.tenderPeriod.startDate,
              endDate=endDate,
              invalidationDate=self.enquiryPeriod
              and self.enquiryPeriod.invalidationDate,
              clarificationsUntil=calculate_business_date(
                  endDate, ENQUIRY_STAND_STILL_TIME, self, True)))
 def complaintPeriod(self):
     if self.tenderPeriod.startDate < COMPLAINT_OLD_SUBMIT_TIME_BEFORE:
         return Period(
             dict(startDate=self.tenderPeriod.startDate,
                  endDate=calculate_business_date(
                      self.tenderPeriod.endDate, -COMPLAINT_OLD_SUBMIT_TIME,
                      self)))
     else:
         normalized_end = calculate_normalized_date(
             self.tenderPeriod.endDate, self)
         return Period(
             dict(startDate=self.tenderPeriod.startDate,
                  endDate=calculate_business_date(normalized_end,
                                                  -COMPLAINT_SUBMIT_TIME,
                                                  self, True)))
Beispiel #4
0
 def collection_post(self):
     """Post a complaint
     """
     tender = self.context
     if tender.status != 'active.tendering':
         self.request.errors.add(
             'body', 'data',
             'Can\'t add complaint in current ({}) tender status'.format(
                 tender.status))
         self.request.errors.status = 403
         return
     complaint = self.request.validated['complaint']
     if complaint.status == 'claim':
         if get_now() > calculate_business_date(tender.tenderPeriod.endDate,
                                                -CLAIM_SUBMIT_TIME, tender,
                                                True):
             self.request.errors.add(
                 'body', 'data',
                 'Can submit claim not later than {0.days} days before tenderPeriod end'
                 .format(CLAIM_SUBMIT_TIME))
             self.request.errors.status = 403
             return
         complaint.dateSubmitted = get_now()
     elif complaint.status == 'pending':
         if get_now() > tender.complaintPeriod.endDate:
             self.request.errors.add(
                 'body', 'data',
                 'Can submit complaint not later than {0.days} days before tenderPeriod end'
                 .format(COMPLAINT_SUBMIT_TIME))
             self.request.errors.status = 403
             return
         complaint.dateSubmitted = get_now()
         complaint.type = 'complaint'
     else:
         complaint.status = 'draft'
     complaint.complaintID = '{}.{}{}'.format(
         tender.tenderID, self.server_id,
         self.complaints_len(tender) + 1)
     set_ownership(complaint, self.request)
     tender.complaints.append(complaint)
     if save_tender(self.request):
         self.LOGGER.info(
             'Created tender complaint {}'.format(complaint.id),
             extra=context_unpack(self.request,
                                  {'MESSAGE_ID': 'tender_complaint_create'},
                                  {'complaint_id': complaint.id}))
         self.request.response.status = 201
         self.request.response.headers['Location'] = self.request.route_url(
             'Tender Complaints',
             tender_id=tender.id,
             complaint_id=complaint.id)
         return {
             'data': complaint.serialize(tender.status),
             'access': {
                 'token': complaint.owner_token
             }
         }
Beispiel #5
0
 def validate_update_tender(self, operation):
     tender = self.request.validated['tender']
     if tender.status not in ['active.tendering']:
         self.request.errors.add(
             'body', 'data',
             'Can\'t {} lot in current ({}) tender status'.format(
                 operation, tender.status))
         self.request.errors.status = 403
         return
     if calculate_business_date(get_now(), TENDERING_EXTRA_PERIOD, tender,
                                True) > tender.tenderPeriod.endDate:
         self.request.errors.add(
             'body', 'data',
             'tenderPeriod should be extended by {0.days} working days'.
             format(TENDERING_EXTRA_PERIOD))
         self.request.errors.status = 403
         return
     return True
 def validate_update_tender(self, operation):
     if self.request.authenticated_role != 'auction' and self.request.validated['tender_status'] != 'active.tendering' or \
        self.request.authenticated_role == 'auction' and self.request.validated['tender_status'] not in ['active.auction', 'active.qualification']:
         self.request.errors.add(
             'body', 'data',
             'Can\'t {} document in current ({}) tender status'.format(
                 operation, self.request.validated['tender_status']))
         self.request.errors.status = 403
         return
     if self.request.validated[
             'tender_status'] == 'active.tendering' and calculate_business_date(
                 get_now(), TENDERING_EXTRA_PERIOD,
                 self.request.validated['tender'], True
             ) > self.request.validated['tender'].tenderPeriod.endDate:
         self.request.errors.add(
             'body', 'data',
             'tenderPeriod should be extended by {0.days} working days'.
             format(TENDERING_EXTRA_PERIOD))
         self.request.errors.status = 403
         return
     return True
 def validate_tenderPeriod(self, data, period):
     if period and calculate_business_date(period.startDate, TENDER_PERIOD,
                                           data, True) > period.endDate:
         raise ValidationError(
             u"tenderPeriod should be greater than {0.days} working days".
             format(TENDER_PERIOD))
Beispiel #8
0
 def patch(self):
     """Post a complaint resolution
     """
     tender = self.request.validated['tender']
     if tender.status != 'active.tendering':
         self.request.errors.add(
             'body', 'data',
             'Can\'t update complaint in current ({}) tender status'.format(
                 tender.status))
         self.request.errors.status = 403
         return
     if self.context.status not in [
             'draft', 'claim', 'answered', 'pending', 'accepted',
             'satisfied', 'stopping'
     ]:
         self.request.errors.add(
             'body', 'data',
             'Can\'t update complaint in current ({}) status'.format(
                 self.context.status))
         self.request.errors.status = 403
         return
     data = self.request.validated['data']
     # complaint_owner
     if self.request.authenticated_role == 'complaint_owner' and self.context.status in [
             'draft', 'claim', 'answered'
     ] and data.get('status', self.context.status) == 'cancelled':
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateCanceled = get_now()
     elif self.request.authenticated_role == 'complaint_owner' and self.context.status in [
             'pending', 'accepted'
     ] and data.get('status', self.context.status) == 'stopping':
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateCanceled = get_now()
     elif self.request.authenticated_role == 'complaint_owner' and tender.status == 'active.tendering' and self.context.status == 'draft' and data.get(
             'status', self.context.status) == self.context.status:
         apply_patch(self.request, save=False, src=self.context.serialize())
     elif self.request.authenticated_role == 'complaint_owner' and tender.status == 'active.tendering' and self.context.status == 'draft' and data.get(
             'status', self.context.status) == 'claim':
         if get_now() > calculate_business_date(tender.tenderPeriod.endDate,
                                                -CLAIM_SUBMIT_TIME, tender,
                                                True):
             self.request.errors.add(
                 'body', 'data',
                 'Can submit claim not later than {0.days} days before tenderPeriod end'
                 .format(CLAIM_SUBMIT_TIME))
             self.request.errors.status = 403
             return
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateSubmitted = get_now()
     elif self.request.authenticated_role == 'complaint_owner' and tender.status == 'active.tendering' and self.context.status in [
             'draft', 'claim'
     ] and data.get('status', self.context.status) == 'pending':
         if get_now() > tender.complaintPeriod.endDate:
             self.request.errors.add(
                 'body', 'data',
                 'Can submit complaint not later than {0.days} days before tenderPeriod end'
                 .format(COMPLAINT_SUBMIT_TIME))
             self.request.errors.status = 403
             return
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.type = 'complaint'
         self.context.dateSubmitted = get_now()
     elif self.request.authenticated_role == 'complaint_owner' and self.context.status == 'answered' and data.get(
             'status', self.context.status) == self.context.status:
         apply_patch(self.request, save=False, src=self.context.serialize())
     elif self.request.authenticated_role == 'complaint_owner' and self.context.status == 'answered' and data.get(
             'satisfied', self.context.satisfied) is True and data.get(
                 'status', self.context.status) == 'resolved':
         apply_patch(self.request, save=False, src=self.context.serialize())
     elif self.request.authenticated_role == 'complaint_owner' and self.context.status == 'answered' and data.get(
             'satisfied', self.context.satisfied) is False and data.get(
                 'status', self.context.status) == 'pending':
         if get_now() > tender.complaintPeriod.endDate:
             self.request.errors.add(
                 'body', 'data',
                 'Can submit complaint not later than {0.days} days before tenderPeriod end'
                 .format(COMPLAINT_SUBMIT_TIME))
             self.request.errors.status = 403
             return
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.type = 'complaint'
         self.context.dateEscalated = get_now()
     # tender_owner
     elif self.request.authenticated_role == 'tender_owner' and self.context.status == 'claim' and data.get(
             'status', self.context.status) == self.context.status:
         now = get_now()
         if now > tender.enquiryPeriod.clarificationsUntil:
             self.request.errors.add(
                 'body', 'data',
                 'Can update claim only before enquiryPeriod.clarificationsUntil'
             )
             self.request.errors.status = 403
             return
         apply_patch(self.request, save=False, src=self.context.serialize())
     elif self.request.authenticated_role == 'tender_owner' and self.context.status == 'satisfied' and data.get(
             'status', self.context.status) == self.context.status:
         apply_patch(self.request, save=False, src=self.context.serialize())
     elif self.request.authenticated_role == 'tender_owner' and self.context.status == 'claim' and data.get(
             'resolution', self.context.resolution) and data.get(
                 'resolutionType',
                 self.context.resolutionType) and data.get(
                     'status', self.context.status) == 'answered':
         now = get_now()
         if now > tender.enquiryPeriod.clarificationsUntil:
             self.request.errors.add(
                 'body', 'data',
                 'Can update claim only before enquiryPeriod.clarificationsUntil'
             )
             self.request.errors.status = 403
             return
         if len(data.get('resolution', self.context.resolution)) < 20:
             self.request.errors.add(
                 'body', 'data',
                 'Can\'t update complaint: resolution too short')
             self.request.errors.status = 403
             return
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateAnswered = get_now()
     elif self.request.authenticated_role == 'tender_owner' and self.context.status in [
             'pending', 'accepted'
     ]:
         apply_patch(self.request, save=False, src=self.context.serialize())
     elif self.request.authenticated_role == 'tender_owner' and self.context.status == 'satisfied' and data.get(
             'tendererAction', self.context.tendererAction) and data.get(
                 'status', self.context.status) == 'resolved':
         apply_patch(self.request, save=False, src=self.context.serialize())
     # aboveThresholdReviewers
     elif self.request.authenticated_role == 'aboveThresholdReviewers' and self.context.status in [
             'pending', 'accepted', 'stopping'
     ] and data.get('status', self.context.status) == self.context.status:
         apply_patch(self.request, save=False, src=self.context.serialize())
     elif self.request.authenticated_role == 'aboveThresholdReviewers' and self.context.status in [
             'pending', 'stopping'
     ] and data.get('status',
                    self.context.status) in ['invalid', 'mistaken']:
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateDecision = get_now()
         self.context.acceptance = False
     elif self.request.authenticated_role == 'aboveThresholdReviewers' and self.context.status == 'pending' and data.get(
             'status', self.context.status) == 'accepted':
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateAccepted = get_now()
         self.context.acceptance = True
     elif self.request.authenticated_role == 'aboveThresholdReviewers' and self.context.status == 'accepted' and data.get(
             'status', self.context.status) in ['declined', 'satisfied']:
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateDecision = get_now()
     elif self.request.authenticated_role == 'aboveThresholdReviewers' and self.context.status == 'stopping' and data.get(
             'status', self.context.status) == 'declined':
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateDecision = get_now()
     elif self.request.authenticated_role == 'aboveThresholdReviewers' and self.context.status in [
             'accepted', 'stopping'
     ] and data.get('status', self.context.status) == 'stopped':
         apply_patch(self.request, save=False, src=self.context.serialize())
         self.context.dateDecision = get_now()
         self.context.dateCanceled = self.context.dateCanceled or get_now()
     else:
         self.request.errors.add('body', 'data', 'Can\'t update complaint')
         self.request.errors.status = 403
         return
     if self.context.tendererAction and not self.context.tendererActionDate:
         self.context.tendererActionDate = get_now()
     if self.context.status not in [
             'draft', 'claim', 'answered', 'pending', 'accepted', 'stopping'
     ] and tender.status in ['active.qualification', 'active.awarded']:
         check_tender_status(self.request)
     if save_tender(self.request):
         self.LOGGER.info(
             'Updated tender complaint {}'.format(self.context.id),
             extra=context_unpack(self.request,
                                  {'MESSAGE_ID': 'tender_complaint_patch'}))
         return {'data': self.context.serialize("view")}
    def patch(self):
        """Update of award

        Example request to change the award:

        .. sourcecode:: http

            PATCH /tenders/4879d3f8ee2443169b5fbbc9f89fa607/awards/71b6c23ed8944d688e92a31ec8c3f61a HTTP/1.1
            Host: example.com
            Accept: application/json

            {
                "data": {
                    "value": {
                        "amount": 600
                    }
                }
            }

        And here is the response to be expected:

        .. sourcecode:: http

            HTTP/1.0 200 OK
            Content-Type: application/json

            {
                "data": {
                    "id": "4879d3f8ee2443169b5fbbc9f89fa607",
                    "date": "2014-10-28T11:44:17.947Z",
                    "status": "active",
                    "suppliers": [
                        {
                            "id": {
                                "name": "Державне управління справами",
                                "scheme": "https://ns.openprocurement.org/ua/edrpou",
                                "uid": "00037256",
                                "uri": "http://www.dus.gov.ua/"
                            },
                            "address": {
                                "countryName": "Україна",
                                "postalCode": "01220",
                                "region": "м. Київ",
                                "locality": "м. Київ",
                                "streetAddress": "вул. Банкова, 11, корпус 1"
                            }
                        }
                    ],
                    "value": {
                        "amount": 600,
                        "currency": "UAH",
                        "valueAddedTaxIncluded": true
                    }
                }
            }

        """
        tender = self.request.validated['tender']
        if tender.status not in ['active.qualification', 'active.awarded']:
            self.request.errors.add(
                'body', 'data',
                'Can\'t update award in current ({}) tender status'.format(
                    tender.status))
            self.request.errors.status = 403
            return
        award = self.request.context
        if any(
            [i.status != 'active' for i in tender.lots
             if i.id == award.lotID]):
            self.request.errors.add(
                'body', 'data', 'Can update award only in active lot status')
            self.request.errors.status = 403
            return
        if any([
                any([c.status == 'accepted' for c in i.complaints])
                for i in tender.awards if i.lotID == award.lotID
        ]):
            self.request.errors.add(
                'body', 'data', 'Can\'t update award with accepted complaint')
            self.request.errors.status = 403
            return
        award_status = award.status
        apply_patch(self.request,
                    save=False,
                    src=self.request.context.serialize())
        if award_status == 'pending' and award.status == 'active':
            normalized_end = calculate_normalized_date(get_now(), tender, True)
            award.complaintPeriod.endDate = calculate_business_date(
                normalized_end, STAND_STILL_TIME, tender, True)
            tender.contracts.append(
                type(tender).contracts.model_class({
                    'awardID':
                    award.id,
                    'suppliers':
                    award.suppliers,
                    'value':
                    award.value,
                    'items':
                    [i for i in tender.items if i.relatedLot == award.lotID],
                    'contractID':
                    '{}-{}{}'.format(tender.tenderID, self.server_id,
                                     len(tender.contracts) + 1)
                }))
            add_next_award(self.request)
        elif award_status == 'active' and award.status == 'cancelled' and any(
            [i.status == 'satisfied' for i in award.complaints]):
            now = get_now()
            cancelled_awards = []
            for i in tender.awards:
                if i.lotID != award.lotID:
                    continue
                if not i.complaintPeriod.endDate or i.complaintPeriod.endDate > now:
                    i.complaintPeriod.endDate = now
                i.status = 'cancelled'
                cancelled_awards.append(i.id)
            for i in tender.contracts:
                if i.awardID in cancelled_awards:
                    i.status = 'cancelled'
            add_next_award(self.request)
        elif award_status == 'active' and award.status == 'cancelled':
            award.complaintPeriod.endDate = get_now()
            for i in tender.contracts:
                if i.awardID == award.id:
                    i.status = 'cancelled'
            add_next_award(self.request)
        elif award_status == 'pending' and award.status == 'unsuccessful':
            normalized_end = calculate_normalized_date(get_now(), tender, True)
            award.complaintPeriod.endDate = calculate_business_date(
                normalized_end, STAND_STILL_TIME, tender, True)
            add_next_award(self.request)
        elif award_status == 'unsuccessful' and award.status == 'cancelled' and any(
            [i.status == 'satisfied' for i in award.complaints]):
            if tender.status == 'active.awarded':
                tender.status = 'active.qualification'
                tender.awardPeriod.endDate = None
            now = get_now()
            if award.complaintPeriod.endDate > now:
                award.complaintPeriod.endDate = now
            cancelled_awards = []
            for i in tender.awards:
                if i.lotID != award.lotID:
                    continue
                i.complaintPeriod.endDate = now
                i.status = 'cancelled'
                cancelled_awards.append(i.id)
            for i in tender.contracts:
                if i.awardID in cancelled_awards:
                    i.status = 'cancelled'
            add_next_award(self.request)
        elif self.request.authenticated_role != 'Administrator' and not (
                award_status == 'pending' and award.status == 'pending'):
            self.request.errors.add(
                'body', 'data',
                'Can\'t update award in current ({}) status'.format(
                    award_status))
            self.request.errors.status = 403
            return
        if save_tender(self.request):
            self.LOGGER.info(
                'Updated tender award {}'.format(self.request.context.id),
                extra=context_unpack(self.request,
                                     {'MESSAGE_ID': 'tender_award_patch'}))
            return {'data': award.serialize("view")}
 def tender_enquiryPeriod(self):
     endDate = calculate_business_date(self.tenderPeriod.endDate, -ENQUIRY_PERIOD_TIME, self, True)
     return EnquiryPeriod(dict(startDate=self.tenderPeriod.startDate,
                               endDate=endDate,
                               invalidationDate=self.enquiryPeriod and self.enquiryPeriod.invalidationDate,
                               clarificationsUntil=calculate_business_date(endDate, ENQUIRY_STAND_STILL_TIME, self, True)))
 def validate_tenderPeriod(self, data, period):
     if period and calculate_business_date(period.startDate, TENDER_PERIOD, data, True) > period.endDate:
         raise ValidationError(u"tenderPeriod should be greater than {0.days} working days".format(TENDER_PERIOD))
    def patch(self):
        """Tender Edit (partial)

        For example here is how procuring entity can change number of items to be procured and total Value of a tender:

        .. sourcecode:: http

            PATCH /tenders/4879d3f8ee2443169b5fbbc9f89fa607 HTTP/1.1
            Host: example.com
            Accept: application/json

            {
                "data": {
                    "value": {
                        "amount": 600
                    },
                    "itemsToBeProcured": [
                        {
                            "quantity": 6
                        }
                    ]
                }
            }

        And here is the response to be expected:

        .. sourcecode:: http

            HTTP/1.0 200 OK
            Content-Type: application/json

            {
                "data": {
                    "id": "4879d3f8ee2443169b5fbbc9f89fa607",
                    "tenderID": "UA-64e93250be76435397e8c992ed4214d1",
                    "dateModified": "2014-10-27T08:12:34.956Z",
                    "value": {
                        "amount": 600
                    },
                    "itemsToBeProcured": [
                        {
                            "quantity": 6
                        }
                    ]
                }
            }

        """
        tender = self.context
        if self.request.authenticated_role != 'Administrator' and tender.status in [
                'complete', 'unsuccessful', 'cancelled'
        ]:
            self.request.errors.add(
                'body', 'data',
                'Can\'t update tender in current ({}) status'.format(
                    tender.status))
            self.request.errors.status = 403
            return
        data = self.request.validated['data']

        if self.request.authenticated_role == 'tender_owner' and self.request.validated[
                'tender_status'] == 'active.tendering':
            if 'tenderPeriod' in data and 'endDate' in data['tenderPeriod']:
                self.request.validated['tender'].tenderPeriod.import_data(
                    data['tenderPeriod'])
                if calculate_business_date(
                        get_now(), TENDERING_EXTRA_PERIOD, tender, True
                ) > self.request.validated['tender'].tenderPeriod.endDate:
                    self.request.errors.add(
                        'body', 'data',
                        'tenderPeriod should be extended by {0.days} working days'
                        .format(TENDERING_EXTRA_PERIOD))
                    self.request.errors.status = 403
                    return
                self.request.validated['tender'].initialize()
                self.request.validated['data'][
                    "enquiryPeriod"] = self.request.validated[
                        'tender'].enquiryPeriod.serialize()

        apply_patch(self.request,
                    save=False,
                    src=self.request.validated['tender_src'])
        if self.request.authenticated_role == 'chronograph':
            check_status(self.request)
        elif self.request.authenticated_role == 'tender_owner' and tender.status == 'active.tendering':
            # invalidate bids on tender change
            tender.invalidate_bids_data()
        save_tender(self.request)
        self.LOGGER.info('Updated tender {}'.format(tender.id),
                         extra=context_unpack(self.request,
                                              {'MESSAGE_ID': 'tender_patch'}))
        return {'data': tender.serialize(tender.status)}