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
    }
Beispiel #2
0
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 test_seller_has_signed_current_agreement_without_old_signed_agreements(self, master_agreements, supplier, user):
        current_agreement = get_current_agreement()

        supplier.signed_agreements = [
            SignedAgreement(
                agreement_id=current_agreement.id,
                user_id=1,
                signed_at=current_agreement.start_date.add(days=2)
            )
        ]

        signed_current_agreement = has_signed_current_agreement(supplier)

        assert signed_current_agreement is True
    def test_seller_has_not_signed_current_agreement_with_old_signed_agreements(self, master_agreements,
                                                                                supplier, user):
        old_agreements = get_old_agreements()

        supplier.signed_agreements = [
            SignedAgreement(
                agreement_id=agreement.id,
                user_id=1,
                signed_at=agreement.start_date.add(days=2)
            )
            for agreement in old_agreements
        ]

        signed_current_agreement = has_signed_current_agreement(supplier)

        assert signed_current_agreement is False
    def test_seller_has_signed_current_agreement_with_old_signed_agreements(self, master_agreements, supplier, user):
        old_agreements = get_old_agreements()
        current_agreement = get_current_agreement()
        past_and_present_agreements = [agreement for agreement in old_agreements]
        past_and_present_agreements.append(current_agreement)

        supplier.signed_agreements = [
            SignedAgreement(
                agreement_id=agreement.id,
                user_id=1,
                signed_at=agreement.start_date.add(days=2)
            )
            for agreement in past_and_present_agreements
        ]

        signed_current_agreement = has_signed_current_agreement(supplier)

        assert signed_current_agreement is True
    def test_seller_has_not_signed_current_agreement_without_any_signed_agreements(self, master_agreements,
                                                                                   supplier, user):
        signed_current_agreement = has_signed_current_agreement(supplier)

        assert signed_current_agreement is False
Beispiel #7
0
    def has_signed_current_agreement(self):
        if self.user_role != 'supplier':
            return True

        return has_signed_current_agreement(self.supplier)