Implement BSB lookup

This commit is contained in:
Yingtong Li 2020-06-16 12:07:52 +10:00
parent 8d31fa1af6
commit 10f0cd4121
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 21 additions and 1 deletions

View File

@ -38,6 +38,9 @@ ABA_BANK_CODE = 0
ABA_SRC_BSB = '000-000'
ABA_SRC_ACC = '00000000'
# Download from http://bsb.apca.com.au/
BSB_FILE_PATH = 'sstreasury/BSBDirectoryMay20-290.csv'
# Application definition
INSTALLED_APPS = [

View File

@ -32,5 +32,6 @@ urlpatterns = [
path('claims/edit/<int:id>', views.claim_edit, name='claim_edit'),
path('claims/action/<int:id>', views.claim_action, name='claim_action'),
path('claims/processing', views.claim_processing, name='claim_processing'),
path('bsb_lookup', views.bsb_lookup, name='bsb_lookup'),
path('', views.index, name='treasury'),
]

View File

@ -22,7 +22,7 @@ from django.core.validators import validate_email
from django.conf import settings
from django.db import transaction
from django.db.models import Q
from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render, redirect
from django.urls import reverse
from django.utils import timezone
@ -33,6 +33,7 @@ from . import models
from . import xero
from ssmain.email import Emailer
import csv
from datetime import datetime
import functools
import io
@ -724,3 +725,18 @@ def claim_processing(request):
return render(request, 'sstreasury/claim_processing.html', {
'claims': claims
})
@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:])})
def do_bsb_lookup(bsb):
with open(settings.BSB_FILE_PATH, 'r', newline='') as f:
reader = csv.reader(f)
for line in reader:
if line[0] == bsb:
return '{} - {}'.format(line[1], line[2])
return None