summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2020-06-15 20:37:43 +1000
committerYingtong Li <runassudo@yingtongli.me>2020-06-15 20:37:43 +1000
commit8d31fa1af6b3fd20e464562fa2d0d5cecb8fdc3f (patch)
tree544de155318070befb9d8466dbdd59438de60fe3
parente28a814edf0da208c97411dc4f93e20dea717861 (diff)
Better ABA handling
-rw-r--r--sstreasury/aba.py40
-rw-r--r--sstreasury/views.py2
2 files changed, 37 insertions, 5 deletions
diff --git a/sstreasury/aba.py b/sstreasury/aba.py
index bd57532..e6c79c5 100644
--- a/sstreasury/aba.py
+++ b/sstreasury/aba.py
@@ -18,9 +18,20 @@
# https://www.cemtexaba.com/aba-format/cemtex-aba-file-format-details
# https://ddkonline.blogspot.com/2009/01/aba-bank-payment-file-format-australian.html
+class ABAException(Exception):
+ pass
+
def write_descriptive(f, reel_seq=1, bank_name='', user_name='', bank_code=0, description='', date=None):
- if reel_seq < 0 or reel_seq > 99 or len(bank_name) > 3 or len(user_name) > 26 or bank_code < 0 or bank_code > 999999 or len(description) > 12:
- raise Exception('Invalid ABA data')
+ if reel_seq < 0 or reel_seq > 99:
+ raise ABAException('Invalid Reel Sequence Number: {}'.format(reel_seq))
+ if len(bank_name) > 3:
+ raise ABAException('Invalid Financial Institution abbreviation: {}'.format(bank_name))
+ if len(user_name) > 26:
+ raise ABAException('Invalid User Preferred Specification: {}'.format(user_name))
+ if bank_code < 0 or bank_code > 999999:
+ raise ABAException('Invalid User Identification Number: {}'.format(bank_code))
+ if len(description) > 12:
+ raise ABAException('Invalid Description: {}'.format(description))
f.write(b'0') # Record Type 0
f.write(b' ' * 17) # Blank
@@ -35,8 +46,29 @@ def write_descriptive(f, reel_seq=1, bank_name='', user_name='', bank_code=0, de
f.write(b'\r\n')
def write_detail(f, dest_bsb='', dest_account='', indicator=' ', transaction_code=53, cents=0, dest_name='', reference='', src_bsb='', src_account='', src_name='', tax_withheld=0):
- if len(dest_bsb.replace('-', '')) != 6 or len(dest_account) > 9 or len(indicator) != 1 or transaction_code < 0 or transaction_code > 99 or len(dest_name) > 32 or len(reference) > 18 or len(src_bsb.replace('-', '')) != 6 or len(src_account) > 9 or len(src_name) > 16:
- raise Exception('Invalid ABA data')
+ dest_bsb = dest_bsb.replace('-', '').replace(' ', '')
+ dest_account = dest_account.replace('-', '').replace(' ', '')
+ src_bsb = src_bsb.replace('-', '').replace(' ', '')
+ src_account = src_account.replace('-', '').replace(' ', '')
+
+ if len(dest_bsb) != 6:
+ raise ABAException('Invalid BSB: {}'.format(dest_bsb))
+ if len(dest_account) > 9:
+ raise ABAException('Invalid Account Number: {}'.format(dest_account))
+ if len(indicator) != 1:
+ raise ABAException('Invalid Indicator: {}'.format(indicator))
+ if transaction_code < 0 or transaction_code > 99:
+ raise ABAException('Invalid Transaction Code: {}'.format(indicator))
+ if len(dest_name) > 32:
+ raise ABAException('Invalid Title of Account: {}'.format(dest_name))
+ if len(reference) > 18:
+ raise ABAException('Invalid Lodgement Reference: {}'.format(reference))
+ if len(src_bsb) != 6:
+ raise ABAException('Invalid Trace BSB: {}'.format(src_bsb))
+ if len(src_account) > 9:
+ raise ABAException('Invalid Trace Account Number: {}'.format(src_account))
+ if len(src_name) > 16:
+ raise ABAException('Invalid Name of Remitter: {}'.format(src_name))
f.write(b'1') # Record Type 1
f.write('{}-{}'.format(dest_bsb[:3], dest_bsb[-3:]).encode('ascii')) # BSB
diff --git a/sstreasury/views.py b/sstreasury/views.py
index f2de186..589d719 100644
--- a/sstreasury/views.py
+++ b/sstreasury/views.py
@@ -669,7 +669,7 @@ def claim_processing(request):
dest_bsb=payee_claims[0].payee_bsb,
dest_account=payee_claims[0].payee_account,
cents=sum(c.get_total() for c in payee_claims)*100,
- dest_name=payee_claims[0].payee_name,
+ dest_name=payee_claims[0].payee_name[:32],
reference='RE{}'.format(' '.join(str(c.id) for c in payee_claims)),
src_bsb=settings.ABA_SRC_BSB,
src_account=settings.ABA_SRC_ACC,
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.