Ejemplo n.º 1
0
def test_cancel_contract_ok(
    process_apartment_application: ApartmentApplication,
    application: Application,
    session: Session,
):
    canceled_on = datetime.now()
    assert process_apartment_application.contract.status == ContractStatus.NEW
    assert not process_apartment_application.contract.tenant_declined
    assert not process_apartment_application.contract.tenant_declined_on
    application.cancel_contract(
        session,
        process_apartment_application,
        canceled_on,
    )
    session.expire_all()
    apartment_application = session.query(ApartmentApplication).get(
        process_apartment_application.id)
    assert apartment_application.status == ApartmentApplicationStatus.FAILED
    assert apartment_application.contract.status == ContractStatus.CANCELED
    assert apartment_application.contract.canceled_on == canceled_on
    assert apartment_application.contract.canceled
Ejemplo n.º 2
0
def signrequest_contract_callback(
    payload: SignrequestEventSchema,
    session: Session = Depends(deps.get_database_session),
    application: Application = Depends(deps.get_application)
    # payload: dict = Body(...)
):
    # event_uuid = payload.uuid
    # event_status = payload.status
    # event_timestamp = payload.timestamp
    # event_hash = payload.event_hash
    # event_document_id = document.uuid
    # document_status = document.status

    # TODO verify hash
    target_event_types = [
        "declined",
        "cancelled",
        "expired",
        "signed",
        "signer_signed",
        "signer_viewed_email",
        "signer_viewed",
    ]
    event_type = payload.event_type
    document = payload.document
    document_signers = document.signrequest.signers
    external_id = document.external_id
    if event_type not in target_event_types:
        return
    apartment_application: ApartmentApplication = session.query(
        ApartmentApplication
    ).get(external_id)
    if not apartment_application:
        return
    if event_type == "expired":
        # TODO get expired on
        application.expire_contract(session, apartment_application, datetime.now())
    elif event_type == "cancelled":
        # TODO get canceld on
        application.cancel_contract(session, apartment_application, datetime.now())
    tenant: Tenant = apartment_application.tenant
    landlord: Landlord = apartment_application.apartment.landlord
    for signer in document_signers:
        if not signer.needs_to_sign:
            continue
        signed_on = signer.signed_on
        signer_declined_on = signer.declined_on
        signer_email = signer.email
        if tenant.email == signer_email:
            if signer.declined:
                application.decline_contract(
                    session, apartment_application, signer_declined_on, tenant
                )
            elif signer.signed:
                application.tenant_signed_contract(
                    session, apartment_application, signed_on
                )

        if landlord.email == signer_email:
            if signer.declined:
                application.decline_contract(
                    session, apartment_application, signer_declined_on, landlord
                )
            elif signer.signed:
                application.landlord_signed_contract(
                    session, apartment_application, signed_on
                )
    return