Пример #1
0
def deposit_edit_submit(request):
    try:
        user = User.from_umid(request.POST['umid'])
        amount = Decimal(request.POST['amount'])
        old_event = Event.from_id(request.POST['old_event_id'])

        if old_event.type != 'deposit' or \
           old_event.transactions[0].type != 'cashdeposit' or \
           (old_event.transactions[0].to_account_virt_id != user.id and \
            old_event.user_id != user.id):
           # Something went wrong, can't undo this deposit
           raise DepositException('Cannot undo that deposit')

        new_deposit = deposit_new(request)

        if 'error' in new_deposit and new_deposit['error'] != 'success':
            # Error occurred, do not delete old event
            return new_deposit

        # Now undo old deposit
        datalayer.undo_event(old_event, user)

        return new_deposit

    except __user.InvalidUserException as e:
        request.session.flash('Invalid user error. Please try again.', 'error')
        return {'redirect_url': '/'}

    except DepositException as e:
        return {'error': str(e)}

    except Exception as e:
        if request.debug: raise(e)
        return {'error': 'Error.'}
Пример #2
0
def terminal_deposit_delete(request):
    try:
        user = User.from_umid(request.POST['umid'])
        old_event = Event.from_id(request.POST['old_event_id'])

        if old_event.type != 'deposit' or \
           old_event.transactions[0].type != 'cashdeposit' or \
           (old_event.transactions[0].to_account_virt_id != user.id and \
            old_event.user_id != user.id):
            # Something went wrong, can't undo this deposit
            raise DepositException('Cannot undo that deposit')

        # Now undo old deposit
        datalayer.undo_event(old_event, user)

        purchase_pools = []
        for pool in Pool.all_by_owner(user, True):
            if pool.balance > (pool.credit_limit * -1):
                purchase_pools.append({
                    'id': pool.id,
                    'balance': float(pool.balance)
                })

        for pu in user.pools:
            if pu.pool.enabled and pu.pool.balance > (pu.pool.credit_limit *
                                                      -1):
                purchase_pools.append({
                    'id': pu.pool.id,
                    'balance': float(pu.pool.balance)
                })

        return {'user_balance': float(user.balance), 'pools': purchase_pools}

    except __user.InvalidUserException as e:
        return {'error': 'Invalid user error. Please try again.'}

    except DepositException as e:
        return {'error': str(e)}

    except Exception as e:
        if request.debug: raise (e)
        return {'error': 'Error.'}
Пример #3
0
def terminal_purchase_delete(request):
    try:
        user = User.from_umid(request.POST['umid'])
        old_event = Event.from_id(request.POST['old_event_id'])

        if old_event.type != 'purchase' or \
           old_event.transactions[0].type != 'purchase' or \
           (old_event.transactions[0].fr_account_virt_id != user.id and \
            old_event.user_id != user.id):
           # Something went wrong, can't undo this purchase
           raise DepositException('Cannot undo that purchase')

        # Now undo old deposit
        datalayer.undo_event(old_event, user)

        return {'user_balance': float(user.balance)}

    except __user.InvalidUserException as e:
        return {'error': 'Invalid user error. Please try again.'}

    except DepositException as e:
        return {'error': str(e)}
Пример #4
0
def terminal_deposit_delete(request):
    try:
        user = User.from_umid(request.POST['umid'])
        old_event = Event.from_id(request.POST['old_event_id'])

        if old_event.type != 'deposit' or \
           old_event.transactions[0].type != 'cashdeposit' or \
           (old_event.transactions[0].to_account_virt_id != user.id and \
            old_event.user_id != user.id):
           # Something went wrong, can't undo this deposit
           raise DepositException('Cannot undo that deposit')

        # Now undo old deposit
        datalayer.undo_event(old_event, user)

        purchase_pools = []
        for pool in Pool.all_by_owner(user, True):
            if pool.balance > (pool.credit_limit * -1):
                purchase_pools.append({'id': pool.id, 'balance': float(pool.balance)})

        for pu in user.pools:
            if pu.pool.enabled and pu.pool.balance > (pu.pool.credit_limit * -1):
                purchase_pools.append({'id': pu.pool.id, 'balance': float(pu.pool.balance)})

        return {'user_balance': float(user.balance),
                'pools': purchase_pools}

    except __user.InvalidUserException as e:
        return {'error': 'Invalid user error. Please try again.'}

    except DepositException as e:
        return {'error': str(e)}

    except Exception as e:
        if request.debug: raise(e)
        return {'error': 'Error.'}
Пример #5
0
def event_undo(request):
    # Lookup the transaction that the user wants to undo
    try:
        event = Event.from_id(request.matchdict['event_id'])
    except:
        request.session.flash('Error: Could not find transaction to undo.', 'error')
        return HTTPFound(location=request.route_url('index'))

    for transaction in event.transactions:

        # Make sure transaction is a deposit, the only one the user is allowed
        # to undo
        if transaction.type not in ('cashdeposit', 'purchase'):
            request.session.flash('Error: Only deposits and purchases may be undone.', 'error')
            return HTTPFound(location=request.route_url('index'))

        # Make sure that the user who is requesting the deposit was the one who
        # actually placed the deposit.
        try:
            user = User.from_id(event.user_id)
        except:
            request.session.flash('Error: Invalid user for transaction.', 'error')
            return HTTPFound(location=request.route_url('index'))

        if user.umid != request.matchdict['umid']:
            request.session.flash('Error: Transaction does not belong to specified user', 'error')
            return HTTPFound(location=request.route_url('user', umid=request.matchdict['umid']))

    # If the checks pass, actually revert the transaction
    try:
        line_items = datalayer.undo_event(event, user)
        if event.type == 'deposit':
            request.session.flash('Deposit successfully undone.', 'success')
        elif event.type == 'purchase':
            request.session.flash('Purchase undone. Please edit it as needed.', 'success')
    except:
        request.session.flash('Error: Failed to undo transaction.', 'error')
        return HTTPFound(location=request.route_url('purchase', umid=user.umid))

    if event.type == 'deposit':
        return HTTPFound(location=request.route_url('user', umid=user.umid))
    elif event.type == 'purchase':
        return HTTPFound(location=request.route_url('purchase', umid=user.umid, _query=line_items))
    else:
        assert(False and "Should not be able to get here?")
Пример #6
0
def admin_event_undo(request):
    # Lookup the transaction that the user wants to undo
    try:
        event = Event.from_id(request.matchdict['event_id'])
    except:
        request.session.flash('Error: Could not find transaction to undo.', 'error')
        return HTTPFound(location=request.route_url('admin_transactions'))

    for transaction in event.transactions:

        # Make sure transaction is a deposit (no user check since admin doing)
        if transaction.type not in ('deposit', 'purchase'):
            request.session.flash('Error: Only deposits and purchases may be undone.', 'error')
            return HTTPFound(location=request.route_url('admin_transactions'))

    # If the checks pass, actually revert the transaction
    try:
        line_items = datalayer.undo_event(event)
        request.session.flash('Transaction successfully reverted.', 'success')
    except:
        request.session.flash('Error: Failed to undo transaction.', 'error')
    return HTTPFound(location=request.route_url('admin_transactions'))