Show BSB lookup on claim page

This commit is contained in:
Yingtong Li 2020-06-16 12:14:49 +10:00
parent 10f0cd4121
commit b2913eac9d
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 26 additions and 8 deletions

View File

@ -87,7 +87,12 @@
</div>
<div class="item">
<i class="building icon"></i>
<div class="content">BSB: {{ claim.payee_bsb }}</div>
<div class="content">
BSB: {{ claim.payee_bsb }}
{% if bsb_lookedup %}
({{ bsb_lookedup }})
{% endif %}
</div>
</div>
<div class="item">
<i class="dollar sign icon"></i>

View File

@ -122,7 +122,12 @@
</div>
<div class="item">
<i class="building icon"></i>
<div class="content">BSB: {{ claim.payee_bsb }}</div>
<div class="content">
BSB: {{ claim.payee_bsb }}
{% if bsb_lookedup %}
({{ bsb_lookedup }})
{% endif %}
</div>
</div>
<div class="item">
<i class="dollar sign icon"></i>

View File

@ -520,10 +520,13 @@ def claim_view(request, claim):
except models.Budget.DoesNotExist:
budget = None
bsb_lookedup = do_bsb_lookup(claim.payee_bsb)
return render(request, 'sstreasury/claim_view.html', {
'claim': claim,
'budget': budget,
'history': history
'history': history,
'bsb_lookedup': bsb_lookedup
})
@login_required
@ -537,9 +540,12 @@ def claim_print(request, claim):
except models.Budget.DoesNotExist:
budget = None
bsb_lookedup = do_bsb_lookup(claim.payee_bsb)
return render(request, 'sstreasury/claim_print.html', {
'claim': claim,
'budget': budget
'budget': budget,
'bsb_lookedup': bsb_lookedup
})
@login_required
@ -728,12 +734,14 @@ def claim_processing(request):
@login_required
def bsb_lookup(request):
bsb = request.GET.get('bsb', '').replace('-', '').replace(' ', '')
if len(bsb) != 6:
return JsonResponse({'result': None})
return JsonResponse({'result': do_bsb_lookup(bsb[:3] + '-' + bsb[-3:])})
return JsonResponse({'result': do_bsb_lookup(request.GET.get('bsb', ''))})
def do_bsb_lookup(bsb):
bsb = (bsb or '').replace('-', '').replace(' ', '')
if len(bsb) != 6:
return None
bsb = '{}-{}'.format(bsb[:3], bsb[-3:])
with open(settings.BSB_FILE_PATH, 'r', newline='') as f:
reader = csv.reader(f)
for line in reader: