Skip to content

Commit

Permalink
Minor fixes to BILL changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptypjeu committed Oct 29, 2024
1 parent b6790a3 commit 79373c5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion teknologr/api/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def get_account(username):
result = __request(f"get?type=user&id={username}")
info = json.loads(result)
info['acc'] = int(info['acc'])
info['balance'] = float(info['balance'])
# Balance is a float, but leave it as a string to avoid having to format it later
# info['balance'] = float(info['balance'])
return info
except BILLException as e:
if e == ERROR_ACCOUNT_DOES_NOT_EXIST:
Expand Down
10 changes: 6 additions & 4 deletions teknologr/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def to_representation(self, instance):
# Add the actual related objects if detail view
# XXX: Do we need to prefetch all related objects here? It's now done earlier, by the caller...
if self.detail:
if self.is_staff:
# Fetch and add BILL id on detail view only
# XXX: 'bill_code' is the wrong term
bill_info = instance.get_bill_info() or {}
data['bill_code'] = bill_info.get('acc')

data['decorations'] = [{
'decoration': {'id': do.decoration.id, 'name': do.decoration.name},
'acquired': do.acquired,
Expand All @@ -87,10 +93,6 @@ def to_representation(self, instance):
'end_date': mt.end_date,
} for mt in instance.member_types.all()]

# Fetch and add BILL id on detail view only
bill_info = instance.get_bill_info() or {}
data['bill_code'] = bill_info.get('acc')

# Modify certain fields if necessary
if hide:
data['given_names'] = instance.get_given_names_with_initials()
Expand Down
4 changes: 2 additions & 2 deletions teknologr/members/templates/member.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<a href="{% url 'api:ldap_account' member.id %}">LDAP</a>
{% endif %}
{% if BILL.acc %}
<a href="{% url 'api:bill' BILL.acc %}">BILL</a>
<a href="{% url 'api:bill' member.id %}">BILL</a>
{% endif %}
{% if bill_admin_url %}
<a href="{{ bill_admin_url }}">BILL admin</a>
Expand Down Expand Up @@ -263,7 +263,7 @@ <h5>BILL</h5>
<span class="monospace">{{ BILL.acc }}</span>
<br/>

<b>Smeknamn:</b> {{ BILL.nick }}
<b>Smeknamn:</b> {{ BILL.nick }}
<br/>

<b>Saldo:</b> {{ BILL.balance }}€
Expand Down
5 changes: 3 additions & 2 deletions teknologr/members/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ def member(request, member_id):

try:
info = bill.get_account(member.username)
context['BILL'] = info
context['bill_admin_url'] = bill.admin_url(info.get('acc'))
if info:
context['BILL'] = info
context['bill_admin_url'] = bill.admin_url(info.get('acc'))
except bill.BILLException as e:
context['BILL'] = {'error': str(e)}

Expand Down

0 comments on commit 79373c5

Please sign in to comment.