def collection_post(self): """Post a complaint """ tender = self.context complaint = self.request.validated["complaint"] if complaint.status == "claim": validate_submit_claim_time(self.request) elif complaint.status == "pending": validate_submit_complaint_time(self.request) complaint.dateSubmitted = get_now() complaint.type = "complaint" else: complaint.status = "draft" complaint.complaintID = "{}.{}{}".format( tender.tenderID, self.server_id, self.complaints_len(tender) + 1) access = 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".format(tender.procurementMethodType), tender_id=tender.id, complaint_id=complaint.id, ) return { "data": complaint.serialize(tender.status), "access": access }
def collection_post(self): """Post a complaint """ tender = self.context complaint = self.request.validated['complaint'] if complaint.status == 'claim': validate_submit_claim_time(self.request) elif complaint.status == 'pending': validate_submit_complaint_time(self.request) 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'.format(tender.procurementMethodType), tender_id=tender.id, complaint_id=complaint.id) return { 'data': complaint.serialize(tender.status), 'access': { 'token': complaint.owner_token } }
def collection_post(self): """Post a complaint """ tender = self.context complaint = self.request.validated['complaint'] if complaint.status == 'claim': validate_submit_claim_time(self.request) elif complaint.status == 'pending': validate_submit_complaint_time(self.request) 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'.format(tender.procurementMethodType), tender_id=tender.id, complaint_id=complaint.id) return { 'data': complaint.serialize(tender.status), 'access': { 'token': complaint.owner_token } }
def patch_as_complaint_owner(self, data): context = self.context status = self.context.status new_status = data.get("status", status) tender = self.request.validated["tender"] apply_rules_2020_04_19 = get_first_revision_date( tender) > RELEASE_2020_04_19 if status in ["draft", "claim", "answered" ] and new_status == "cancelled": apply_patch(self.request, save=False, src=context.serialize()) context.dateCanceled = get_now() elif (apply_rules_2020_04_19 and status == "draft" and context.type == "complaint" and new_status == "mistaken"): context.rejectReason = "cancelledByComplainant" apply_patch(self.request, save=False, src=context.serialize()) elif (status in ["pending", "accepted"] and new_status == "stopping" and not apply_rules_2020_04_19): apply_patch(self.request, save=False, src=context.serialize()) context.dateCanceled = get_now() elif (tender.status == "active.tendering" and status == "draft" and new_status == status): apply_patch(self.request, save=False, src=context.serialize()) elif (tender.status == "active.tendering" and status == "draft" and new_status == "claim"): self.validate_submit_claim_time_method(self.request) apply_patch(self.request, save=False, src=context.serialize()) context.dateSubmitted = get_now() elif (tender.status == "active.tendering" and status in ["draft", "claim"] and new_status == "pending" and not apply_rules_2020_04_19): validate_submit_complaint_time(self.request) validate_complaint_type_change(self.request) apply_patch(self.request, save=False, src=context.serialize()) context.type = "complaint" context.dateSubmitted = get_now() elif status == "answered" and new_status == status: apply_patch(self.request, save=False, src=context.serialize()) elif (status == "answered" and data.get("satisfied", context.satisfied) is True and new_status == "resolved"): apply_patch(self.request, save=False, src=context.serialize()) elif (status == "answered" and data.get("satisfied", context.satisfied) is False and new_status == "pending"): validate_submit_complaint_time(self.request) validate_complaint_type_change(self.request) apply_patch(self.request, save=False, src=context.serialize()) context.type = "complaint" context.dateEscalated = get_now() else: raise_operation_error( self.request, "Can't update complaint from {} to {} status".format( status, new_status))
def pre_create(self): complaint = self.request.validated["complaint"] complaint.date = get_now() if complaint.status == "claim": self.validate_submit_claim_time_method(self.request) complaint.dateSubmitted = get_now() elif complaint.status == "pending": validate_submit_complaint_time(self.request) complaint.dateSubmitted = get_now() complaint.type = "complaint" else: complaint.status = "draft" return complaint
def pre_create(self): tender = self.request.validated["tender"] old_rules = get_first_revision_date(tender) < RELEASE_2020_04_19 complaint = self.request.validated["complaint"] complaint.date = get_now() if complaint.status == "claim" and complaint.type == "claim": self.validate_submit_claim_time_method(self.request) complaint.dateSubmitted = get_now() elif old_rules and complaint.status == "pending": validate_submit_complaint_time(self.request) complaint.dateSubmitted = get_now() complaint.type = "complaint" else: complaint.status = "draft" return complaint
def patch(self): """Post a complaint resolution """ tender = self.request.validated["tender"] 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"): validate_submit_claim_time(self.request) 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"): validate_submit_complaint_time(self.request) 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"): validate_submit_complaint_time(self.request) 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): validate_update_claim_time(self.request) 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"): validate_update_claim_time(self.request) if len(data.get("resolution", self.context.resolution)) < 20: raise_operation_error( self.request, "Can't update complaint: resolution too short") 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 in ["accepted", "stopping"] 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 in ["pending", "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: raise_operation_error(self.request, "Can't update complaint") 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")}