def send_evidence_assessment_rejection_notification(evidence): template_filename = 'evidence_assessment_rejected.md' frontend_address = current_app.config['FRONTEND_ADDRESS'] domain = domain_service.find(id=evidence.domain_id).one_or_none() user = users.find(id=evidence.user_id).one_or_none() if not domain or not user: raise Exception('invalid domain id or user id') email_addresses = [user.email_address] # prepare copy email_body = render_email_template(template_filename, domain_name=domain.name, frontend_address=frontend_address) subject = "Outcome of assessment for %s" % (domain.name) send_or_handle_error( email_addresses, email_body, subject, current_app.config['DM_GENERIC_NOREPLY_EMAIL'], current_app.config['DM_GENERIC_SUPPORT_NAME'], event_description_for_errors='evidence assessment approved')
def send_evidence_assessment_requested_notification(evidence_id, domain_id, user_email): template_filename = 'evidence_assessment_requested.md' frontend_address = current_app.config['FRONTEND_ADDRESS'] domain = domain_service.find(id=domain_id).one_or_none() if not domain: raise Exception('invalid domain id') email_addresses = [user_email] # prepare copy email_body = render_email_template(template_filename, frontend_address=frontend_address, domain_name=domain.name, evidence_id=evidence_id, current_user_email=user_email) subject = "Assessment request for %s received" % (domain.name) send_or_handle_error( email_addresses, email_body, subject, current_app.config['DM_GENERIC_NOREPLY_EMAIL'], current_app.config['DM_GENERIC_SUPPORT_NAME'], event_description_for_errors='evidence assessment approved')
def __init__(self, domain_id=None, rate=None): self.domain = domain_service.find(id=domain_id).one_or_none() if not self.domain: raise DomainCriteriaInvalidDomainException('Invalid domain id') if not rate or not str(rate).isdigit(): raise DomainCriteriaInvalidRateException('Invalid rate') self.rate = int(rate)
def create(current_user): lot = lots_service.find(slug='training2').one_or_none() framework = frameworks_service.find( slug='digital-marketplace').one_or_none() user = users.get(current_user.id) agency_name = '' email_domain = user.email_address.split('@')[1] agency = agency_service.find(domain=email_domain).one_or_none() if agency: agency_name = agency.name domain = domain_service.find( name='Training, Learning and Development').one_or_none() seller_category = None if domain: seller_category = str(domain.id) else: raise Exception('Training, Learning and Development domain not found') brief = briefs.create_brief(user, current_user.get_team(), framework, lot, data={ 'organisation': agency_name, 'sellerCategory': seller_category }) audit_service.log_audit_event(audit_type=audit_types.create_brief, user=current_user.email_address, data={'briefId': brief.id}, db_object=brief) return brief
def validate_seller_category(self): if not self.data['sellerCategory'].replace(' ', ''): return False domain_ids = [ d.id for d in domain_service.find(name='Training, Learning and Development').all() ] return True if int(self.data['sellerCategory']) in domain_ids else False
def approve_domain(self): supplier = suppliers.get_supplier_by_code(self.evidence.supplier_code) if not supplier: raise DomainApprovalException('Invalid suppier code in evidence') domain = domain_service.find(id=self.evidence.domain_id).one_or_none() if not domain: raise DomainApprovalException('Invalid domain id in evidence') # insert the supplier_domain as assessed for this supplier and domain supplier_domain_service.set_supplier_domain_status( supplier.id, domain.id, 'assessed', 'approved', do_commit=False ) # set the evidence as approved self.evidence.approve() evidence_service.save_evidence(self.evidence, do_commit=False) # update the supplier's pricing for the evidence's domain supplier_data = supplier.data.copy() if 'pricing' not in supplier_data: supplier_data['pricing'] = {} supplier_data['pricing'][domain.name] = {'maxPrice': str(self.evidence.data['maxDailyRate'])} supplier.data.update({'pricing': supplier_data['pricing']}) suppliers.save_supplier(supplier, do_commit=False) # create the evidence assessment outcome evidence_assessment = evidence_assessment_service.create_assessment( evidence_id=self.evidence.id, user_id=self.actioned_by, status='approved', do_commit=False ) self.__commit() try: publish_tasks.evidence.delay( publish_tasks.compress_evidence(self.evidence), 'approved', actioned_by=self.actioned_by, evidence_assessment=evidence_assessment.serialize(), domain=domain.name, supplier_code=supplier.code ) except Exception as e: pass return evidence_assessment