def get_agreement_status(supplier, user_info): email_address = user_info.get('email_address') show_agreement = False can_sign_agreement = False signed_agreement = False can_user_sign_agreement = False new_agreement = None start_date = pendulum.now('Australia/Canberra').date() agreement = get_current_agreement() new_agreement = get_new_agreement() signed = has_signed_current_agreement(supplier) if agreement: now = pendulum.now('Australia/Canberra').date() start_date = (pendulum.parse(agreement.get('startDate'), tz='Australia/Canberra').date()) show_agreement = True can_sign_agreement = True signed_agreement = True if signed else False can_user_sign_agreement = (True if supplier.data.get('email') == email_address else False) return { 'show': show_agreement, 'canSign': can_sign_agreement, 'canUserSign': can_user_sign_agreement, 'signed': signed_agreement, 'startDate': start_date.strftime('%Y-%m-%d'), 'currentAgreement': agreement, 'newAgreement': new_agreement }
def get_supplier_messages(code, skip_application_check): applications = application_service.find( supplier_code=code, type='edit' ).all() supplier = suppliers.get_supplier_by_code(code) validation_result = SupplierValidator(supplier).validate_all() if any([a for a in applications if a.status == 'saved']): validation_result.warnings.append({ 'message': 'You have saved updates on your profile. ' 'You must submit these changes to the Marketplace for review. ' 'If you did not make any changes, select \'Discard all updates\'.', 'severity': 'warning', 'step': 'update', 'id': 'SB001' }) if not skip_application_check: if any([a for a in applications if a.status == 'submitted']): del validation_result.warnings[:] del validation_result.errors[:] if not has_signed_current_agreement(supplier): if get_current_agreement(): message = ( 'Your authorised representative {must accept the new Master Agreement} ' 'before you can apply for opportunities.' ) validation_result.errors.append({ 'message': message, 'severity': 'error', 'step': 'representative', 'id': 'SB002', 'links': { 'must accept the new Master Agreement': '/2/seller-edit/{}/representative'.format(code) } }) else: new_master_agreement = get_new_agreement() if new_master_agreement: start_date = new_master_agreement.start_date.in_tz('Australia/Canberra').date() message = ( 'From {}, your authorised representative must ' 'accept the new Master Agreement ' 'before you can apply for opportunities.' ).format(start_date.strftime('%-d %B %Y')) validation_result.warnings.append({ 'message': message, 'severity': 'warning', 'step': 'representative', 'id': 'SB002' }) return validation_result
def send_notify_auth_rep_email(supplier_code): from app.api.services import ( audit_service, audit_types, suppliers, key_values_service ) supplier = suppliers.get_supplier_by_code(supplier_code) to_address = supplier.data.get('email', '').encode('utf-8') agreement = get_new_agreement() if agreement is None: agreement = get_current_agreement() start_date = pendulum.now('Australia/Canberra').date() if agreement: start_date = agreement.start_date.in_tz('Australia/Canberra') # prepare copy email_body = render_email_template( 'seller_edit_notify_auth_rep.md', ma_start_date=start_date.strftime('%-d %B %Y'), supplier_name=supplier.name, supplier_code=supplier.code, auth_rep_name=escape_markdown(supplier.data.get('representative', '')), frontend_url=current_app.config['FRONTEND_ADDRESS'] ) subject = "Accept the Master Agreement for the Digital Marketplace" send_or_handle_error( to_address, email_body, subject, current_app.config['DM_GENERIC_NOREPLY_EMAIL'], current_app.config['DM_GENERIC_SUPPORT_NAME'], event_description_for_errors='notify auth rep email' ) audit_service.log_audit_event( audit_type=audit_types.notify_auth_rep_accept_master_agreement, user='', data={ "to_address": to_address, "email_body": email_body, "subject": subject }, db_object=supplier)
def test_new_agreement_start_date_is_in_the_future(self, master_agreements): new_agreement = get_new_agreement() now = pendulum.now('utc') assert new_agreement.start_date > now