def evidence_id_rejected(self): if self.has_latest_evidence_rejected_for_category(): evidence = evidence_service.get_latest_evidence_for_supplier_and_domain( int(self.brief_category), self.supplier_code) if evidence and evidence.status == 'rejected': return evidence.id return None
def has_latest_evidence_rejected_for_category(self): if self.supplier and self.brief_category: evidence = evidence_service.get_latest_evidence_for_supplier_and_domain( int(self.brief_category), self.supplier_code) if evidence and evidence.status == 'rejected': return True return False
def is_awaiting_domain_assessment(self): if self.supplier and self.brief_category: evidence = evidence_service.get_latest_evidence_for_supplier_and_domain( int(self.brief_category), self.supplier_code) if evidence and evidence.status == 'submitted': return True if (self.supplier and self.brief_category and self.brief.data.get('openTo', '') == 'all' and assessments.get_open_assessments( domain_id=int(self.brief_category), supplier_code=self.supplier_code)): return True return False
def create_evidence(domain_id, brief_id=None): """Create evidence (role=supplier) --- tags: - evidence definitions: EvidenceCreated: type: object properties: id: type: number domain_id: type: number supplier_code: type: number responses: 200: description: Evidence created successfully. schema: $ref: '#/definitions/EvidenceCreated' 400: description: Bad request. 403: description: Unauthorised to create evidence. 500: description: Unexpected error. """ domain = domain_service.get_by_name_or_id(domain_id, show_legacy=False) if not domain: abort('Unknown domain id') supplier = suppliers.get_supplier_by_code(current_user.supplier_code) if supplier.data.get('recruiter', '') == 'yes': abort('Assessment can\'t be started against a recruiter only supplier') existing_evidence = evidence_service.get_latest_evidence_for_supplier_and_domain( domain_id, current_user.supplier_code) if domain.name in supplier.assessed_domains: abort('This supplier is already assessed for this domain') open_assessment = assessments.get_open_assessments( domain_id=domain_id, supplier_code=current_user.supplier_code) if open_assessment or (existing_evidence and existing_evidence.status in ['draft', 'submitted']): abort( 'This supplier already has a draft assessment or is awaiting assessment for this domain' ) if brief_id: brief = briefs.find(id=brief_id).one_or_none() if not brief or brief.status != 'live': abort('Brief id does not exist or is not open for responses') try: data = {} if existing_evidence and existing_evidence.status == 'rejected': data = existing_evidence.data.copy() else: # does this supplier already have a max price for this domain set? if so, pre-populate current_max_price = suppliers.get_supplier_max_price_for_domain( current_user.supplier_code, domain.name) if current_max_price: data['maxDailyRate'] = int(current_max_price) evidence = evidence_service.create_evidence(domain_id, current_user.supplier_code, current_user.id, brief_id=brief_id, data=data) except Exception as e: rollbar.report_exc_info() abort(e.message) publish_tasks.evidence.delay(publish_tasks.compress_evidence(evidence), 'created', name=current_user.name, domain=domain.name, supplier_code=current_user.supplier_code) return jsonify(evidence.serialize())
def get_evidence_feedback(evidence_id): evidence = evidence_service.get_evidence_by_id(evidence_id) if not evidence or current_user.supplier_code != evidence.supplier_code: not_found("No evidence for id '%s' found" % (evidence_id)) if not evidence.status == 'rejected': abort('Only rejected submissions can contain feedback') evidence_assessment = evidence_assessment_service.get_assessment_for_rejected_evidence( evidence_id) if not evidence_assessment: abort('Failed to get the evidence assessment') try: domain_criteria = DomainCriteria(domain_id=evidence.domain.id, rate=evidence.data.get( 'maxDailyRate', None)) criteria_needed = domain_criteria.get_criteria_needed() except Exception as e: abort(str(e)) criteria_from_domain = {} domain_criteria = domain_criteria_service.get_criteria_by_domain_id( evidence.domain.id) for criteria in domain_criteria: criteria_from_domain[str(criteria.id)] = criteria.name criteria = {} failed_criteria = evidence_assessment.data.get('failed_criteria', {}) vfm = evidence_assessment.data.get('vfm', None) for criteria_id, criteria_response in evidence.get_criteria_responses( ).iteritems(): has_feedback = True if criteria_id in failed_criteria.keys() else False criteria[criteria_id] = { "response": criteria_response, "name": criteria_from_domain[criteria_id] if criteria_id in criteria_from_domain else '', "has_feedback": has_feedback, "assessment": failed_criteria[criteria_id] if has_feedback else {} } current_evidence = evidence_service.get_latest_evidence_for_supplier_and_domain( evidence.domain.id, current_user.supplier_code) data = { 'domain_id': evidence.domain.id, 'domain_name': evidence.domain.name, 'criteria': criteria, 'criteria_needed': criteria_needed, 'current_evidence_id': current_evidence.id if current_evidence.status == 'draft' else None, 'vfm': vfm } return jsonify(data)
def get_categories(): categories = [] supplier = suppliers.get_supplier_by_code(current_user.supplier_code) for domain in domain_service.get_active_domains(): is_approved = True if domain.name in supplier.assessed_domains else False data = { "id": domain.id, "name": domain.name, "previous_evidence_id": None, "evidence_id": None, "is_approved": is_approved } domain_evidence = evidence_service.get_latest_evidence_for_supplier_and_domain( domain.id, current_user.supplier_code, ) if domain_evidence: previous_evidence = evidence_service.get_previous_submitted_evidence_for_supplier_and_domain( domain_evidence.id, domain.id, current_user.supplier_code) if previous_evidence and previous_evidence.status == 'rejected': data['previous_evidence_id'] = previous_evidence.id data['status'] = domain_evidence.status data['evidence_id'] = domain_evidence.id else: # is there a submitted case study assessment in progress? open_assessment = assessments.get_open_assessments( domain_id=domain.id, supplier_code=supplier.code) if open_assessment: data['status'] = 'submitted' else: assessed_status = suppliers.get_supplier_assessed_status( supplier.id, domain.id) data[ 'status'] = assessed_status if assessed_status else 'unassessed' # override the status as unassessed if the domain is not in the assessed domains if data['status'] == 'assessed' and not is_approved: data['status'] = 'unassessed' data['rate'] = suppliers.get_supplier_max_price_for_domain( current_user.supplier_code, domain.name) categories.append(data) # sort by status categories_sorted = [] categories_sorted += [ x for x in categories if x['status'] == 'rejected' ] categories_sorted += [x for x in categories if x['status'] == 'draft'] categories_sorted += [ x for x in categories if x['status'] == 'submitted' ] categories_sorted += [ x for x in categories if x['status'] == 'assessed' ] categories_sorted += [ x for x in categories if x['status'] == 'unassessed' ] return jsonify(categories={'items': categories_sorted}), 200
def evidence_id_in_draft(self): if self.has_evidence_in_draft_for_category(): evidence = evidence_service.get_latest_evidence_for_supplier_and_domain( int(self.brief_category), self.supplier_code) return evidence.id return None
def get_categories(): """Supplier dashboard (Categories) (role=supplier) --- tags: - dashboard definitions: SellerDashboardCategoryItems: type: object properties: categories: type: array items: $ref: '#/definitions/SellerDashboardCategoryItem' SellerDashboardCategoryItem: type: object properties: id: type: number name: type: string status: type: string is_approved: type: boolean evidence_id: type: number responses: 200: description: Seller dashboard data for the 'Categories' tab schema: $ref: '#/definitions/SellerDashboardCategoryItems' """ categories = [] supplier = suppliers.get_supplier_by_code(current_user.supplier_code) for domain in domain_service.get_active_domains(): is_approved = True if domain.name in supplier.assessed_domains else False data = { "id": domain.id, "name": domain.name, "previous_evidence_id": None, "evidence_id": None, "is_approved": is_approved } domain_evidence = evidence_service.get_latest_evidence_for_supplier_and_domain( domain.id, current_user.supplier_code, ) if domain_evidence: previous_evidence = evidence_service.get_previous_submitted_evidence_for_supplier_and_domain( domain_evidence.id, domain.id, current_user.supplier_code) if previous_evidence and previous_evidence.status == 'rejected': data['previous_evidence_id'] = previous_evidence.id data['status'] = domain_evidence.status data['evidence_id'] = domain_evidence.id else: # is there a submitted case study assessment in progress? open_assessment = assessments.get_open_assessments( domain_id=domain.id, supplier_code=supplier.code) if open_assessment: data['status'] = 'submitted' else: assessed_status = suppliers.get_supplier_assessed_status( supplier.id, domain.id) data[ 'status'] = assessed_status if assessed_status else 'unassessed' # override the status as unassessed if the domain is not in the assessed domains if data['status'] == 'assessed' and not is_approved: data['status'] = 'unassessed' data['rate'] = suppliers.get_supplier_max_price_for_domain( current_user.supplier_code, domain.name) categories.append(data) # sort by status categories_sorted = [] categories_sorted += [ x for x in categories if x['status'] == 'rejected' ] categories_sorted += [x for x in categories if x['status'] == 'draft'] categories_sorted += [ x for x in categories if x['status'] == 'submitted' ] categories_sorted += [ x for x in categories if x['status'] == 'assessed' ] categories_sorted += [ x for x in categories if x['status'] == 'unassessed' ] return jsonify(categories={'items': categories_sorted}), 200