diff --git a/teknologr/api/bill.py b/teknologr/api/bill.py index 0b4498b..5bef17d 100644 --- a/teknologr/api/bill.py +++ b/teknologr/api/bill.py @@ -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: diff --git a/teknologr/api/serializers.py b/teknologr/api/serializers.py index fc498d4..ae50999 100644 --- a/teknologr/api/serializers.py +++ b/teknologr/api/serializers.py @@ -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, @@ -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() diff --git a/teknologr/members/templates/member.html b/teknologr/members/templates/member.html index 5b1cd3a..e8d1f0d 100644 --- a/teknologr/members/templates/member.html +++ b/teknologr/members/templates/member.html @@ -15,7 +15,7 @@ LDAP {% endif %} {% if BILL.acc %} - BILL + BILL {% endif %} {% if bill_admin_url %} BILL admin @@ -263,7 +263,7 @@
BILL
{{ BILL.acc }}
- Smeknamn: {{ BILL.nick }}€ + Smeknamn: {{ BILL.nick }}
Saldo: {{ BILL.balance }}€ diff --git a/teknologr/members/views.py b/teknologr/members/views.py index 7a29c3f..89bd42e 100644 --- a/teknologr/members/views.py +++ b/teknologr/members/views.py @@ -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)}