summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2020-06-16 12:07:52 +1000
committerYingtong Li <runassudo@yingtongli.me>2020-06-16 12:11:30 +1000
commit10f0cd4121c2e920ff18e7c02b8ceefd7d8ccb5d (patch)
tree7eae3654d183087d66f55d666220d1c6e89dfcd9
parent8d31fa1af6b3fd20e464562fa2d0d5cecb8fdc3f (diff)
Implement BSB lookup
-rw-r--r--selfserv/settings.example.py3
-rw-r--r--sstreasury/urls.py1
-rw-r--r--sstreasury/views.py18
3 files changed, 21 insertions, 1 deletions
diff --git a/selfserv/settings.example.py b/selfserv/settings.example.py
index 4c53afb..bae5801 100644
--- a/selfserv/settings.example.py
+++ b/selfserv/settings.example.py
@@ -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 = [
diff --git a/sstreasury/urls.py b/sstreasury/urls.py
index 629ef12..b70feba 100644
--- a/sstreasury/urls.py
+++ b/sstreasury/urls.py
@@ -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'),
]
diff --git a/sstreasury/views.py b/sstreasury/views.py
index 589d719..d3b1d7c 100644
--- a/sstreasury/views.py
+++ b/sstreasury/views.py
@@ -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
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.