Better ABA handling
This commit is contained in:
parent
e28a814edf
commit
8d31fa1af6
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user