Skip to content

Commit

Permalink
add link to relevant transactions for reimbursee
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Sep 4, 2016
1 parent 3d5cab6 commit 0f4b084
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 81 deletions.
91 changes: 32 additions & 59 deletions chezbetty/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,78 +354,51 @@ def __total_purchase_amount(self):
# This is in a stupid place due to circular input problems
@classmethod
@limitable_all
def __get_cash_events(cls):
return DBSession.query(event.Event)\
.join(Transaction)\
.filter(or_(
Transaction.to_account_cash_id == account.get_cash_account("chezbetty").id,
Transaction.fr_account_cash_id == account.get_cash_account("chezbetty").id))\
.filter(event.Event.deleted==False)\
.order_by(desc(event.Event.timestamp))
event.Event.get_cash_events = __get_cash_events
def __get_events_by_type(cls, event_type):
q = DBSession.query(event.Event)\
.join(Transaction)

# This is in a stupid place due to circular input problems
@classmethod
@limitable_all
def __get_restock_events(cls):
return DBSession.query(event.Event)\
.join(Transaction)\
.filter(Transaction.type == 'restock')\
.filter(event.Event.deleted==False)\
.order_by(desc(event.Event.timestamp))
event.Event.get_restock_events = __get_restock_events

# This is in a stupid place due to circular input problems
@classmethod
@limitable_all
def __get_emptycash_events(cls):
return DBSession.query(event.Event)\
.join(Transaction)\
.filter(or_(
if event_type == 'cash':
q = q.filter(or_(
Transaction.to_account_cash_id == account.get_cash_account("chezbetty").id,
Transaction.fr_account_cash_id == account.get_cash_account("chezbetty").id))
elif event_type == 'restock':
q = q.filter(Transaction.type == 'restock')
elif event_type == 'emptycash':
q = q.filter(or_(
Transaction.type == 'emptycashbox',
Transaction.type == 'emptysafe',
Transaction.type == 'emptybitcoin'))\
.filter(event.Event.deleted==False)\
.order_by(desc(event.Event.timestamp))
event.Event.get_emptycash_events = __get_emptycash_events

# This is in a stupid place due to circular input problems
@classmethod
@limitable_all
def __get_deposit_events(cls):
return DBSession.query(event.Event)\
.join(Transaction)\
.filter(or_(
Transaction.type == 'emptybitcoin'))
elif event_type == 'deposit':
q = q.filter(or_(
Transaction.type == 'cashdeposit',
Transaction.type == 'ccdeposit',
Transaction.type == 'btcdeposit'))\
.filter(event.Event.deleted==False)\
.order_by(desc(event.Event.timestamp))
event.Event.get_deposit_events = __get_deposit_events

# This is in a stupid place due to circular input problems
@classmethod
@limitable_all
def __get_donation_events(cls):
return DBSession.query(event.Event)\
.join(Transaction)\
.filter(or_(
Transaction.type == 'btcdeposit'))
elif event_type == 'donation':
q = q.filter(or_(
Transaction.type == 'donation',
Transaction.type == 'withdrawal'))\
.filter(event.Event.deleted==False)\
.order_by(desc(event.Event.timestamp))
event.Event.get_donation_events = __get_donation_events
Transaction.type == 'withdrawal'))
elif event_type == 'reimbursement':
q = q.filter(Transaction.type == 'reimbursement')

q = q.filter(event.Event.deleted==False)\
.order_by(desc(event.Event.timestamp))
return q
event.Event.get_events_by_type = __get_events_by_type

# This is in a stupid place due to circular input problems
@classmethod
@limitable_all
def __get_reimbursement_events(cls):
return DBSession.query(event.Event)\
def __get_events_by_cashaccount(cls, account_id):
q = DBSession.query(event.Event)\
.join(Transaction)\
.filter(Transaction.type == 'reimbursement')\
.filter(or_(
Transaction.to_account_cash_id == account_id,
Transaction.fr_account_cash_id == account_id))\
.filter(event.Event.deleted==False)\
.order_by(desc(event.Event.timestamp))
event.Event.get_reimbursement_events = __get_reimbursement_events
return q
event.Event.get_events_by_cashaccount = __get_events_by_cashaccount

# This is in a stupid place due to circular input problems
@classmethod
Expand Down
14 changes: 7 additions & 7 deletions chezbetty/templates/admin/events_menu.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<ul class="nav navbar-nav">
<li {% if event_filter == 'all' %}class="active"{% endif %}><a href="/admin/events">All Transactions</a></li>
{% if request.has_permission("admin") %}
<li {% if event_filter == 'deleted' %}class="active"{% endif %}><a href="/admin/events?filter=deleted">Deleted Transactions</a></li>
<li {% if event_filter == 'cash' %}class="active"{% endif %}><a href="/admin/events?filter=cash">Cash Transactions</a></li>
<li {% if event_filter == 'restock' %}class="active"{% endif %}><a href="/admin/events?filter=restock">Restocks</a></li>
<li {% if event_filter == 'emptycash' %}class="active"{% endif %}><a href="/admin/events?filter=emptycash">Cashbox Empties</a></li>
<li {% if event_filter == 'deposit' %}class="active"{% endif %}><a href="/admin/events?filter=deposit">Deposits</a></li>
<li {% if event_filter == 'donation' %}class="active"{% endif %}><a href="/admin/events?filter=donation">Donations/Withdrawals</a></li>
<li {% if event_filter == 'reimbursement' %}class="active"{% endif %}><a href="/admin/events?filter=reimbursement">Reimbursements</a></li>
<li {% if event_filter == 'status:deleted' %}class="active"{% endif %}><a href="/admin/events?filter=status:deleted">Deleted Transactions</a></li>
<li {% if event_filter == 'type:cash' %}class="active"{% endif %}><a href="/admin/events?filter=type:cash">Cash Transactions</a></li>
<li {% if event_filter == 'type:restock' %}class="active"{% endif %}><a href="/admin/events?filter=type:restock">Restocks</a></li>
<li {% if event_filter == 'type:emptycash' %}class="active"{% endif %}><a href="/admin/events?filter=type:emptycash">Cashbox Empties</a></li>
<li {% if event_filter == 'type:deposit' %}class="active"{% endif %}><a href="/admin/events?filter=type:deposit">Deposits</a></li>
<li {% if event_filter == 'type:donation' %}class="active"{% endif %}><a href="/admin/events?filter=type:donation">Donations/Withdrawals</a></li>
<li {% if event_filter == 'type:reimbursement' %}class="active"{% endif %}><a href="/admin/events?filter=type:reimbursement">Reimbursements</a></li>
{% endif %}
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion chezbetty/templates/admin/reimbursees.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

{% for reimbursee in reimbursees %}
<tr id="reimbursee-{{ reimbursee.id }}" class="reimbursee-row">
<td>{{ reimbursee.name }}</td>
<td><a href="/admin/events?filter=cash_account:{{ reimbursee.id }}">{{ reimbursee.name }}</a></td>
<td>{{ reimbursee.balance|format_currency|safe }}</td>
</tr>
{% endfor %}
Expand Down
28 changes: 14 additions & 14 deletions chezbetty/views_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2795,20 +2795,20 @@ def admin_btc_reconcile_submit(request):


def _get_event_filter_function(event_filter):
if event_filter in (
'deleted',
'cash',
'restock',
'emptycash',
'deposit',
'donation',
'reimbursement'
):
try:
return getattr(Event, 'get_'+event_filter+'_events')
except AttributeError:
request.session.flash('Ignoring invalid filter', 'error')
return Event.all
fields = event_filter.split(':')
if fields[0] == 'type':
def filterfn (*args, **kwargs):
return Event.get_events_by_type(fields[1], *args, **kwargs)
return filterfn
elif fields[0] == 'status':
if fields[1] == 'deleted':
return Event.get_deleted_events
elif fields[0] == 'cash_account':
def filterfn (*args, **kwargs):
return Event.get_events_by_cashaccount(int(fields[1]), *args, **kwargs)
return filterfn
else:
return Event.all


@view_config(route_name='admin_events',
Expand Down

0 comments on commit 0f4b084

Please sign in to comment.