Display ABA errors on export page

This commit is contained in:
Yingtong Li 2021-03-02 10:16:09 +11:00
parent 44ba18d22e
commit 6be52fb718
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 41 additions and 29 deletions

View File

@ -2,7 +2,7 @@
{# {#
Society Self-Service Society Self-Service
Copyright © 2018–2020 Yingtong Li (RunasSudo) Copyright © 2018–2021 Yingtong Li (RunasSudo)
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by it under the terms of the GNU Affero General Public License as published by
@ -23,6 +23,12 @@
{% block maincontent %} {% block maincontent %}
<h1>Claims processing</h1> <h1>Claims processing</h1>
{% if error %}
<div class="ui error message">
An error occurred while generating the ABA file: {{ error }}
</div>
{% endif %}
<form class="ui form" method="POST"> <form class="ui form" method="POST">
<button class="ui small primary labeled icon button" type="submit" name="action" value="Export"><i class="download icon"></i>Export selected to ABA</button> <button class="ui small primary labeled icon button" type="submit" name="action" value="Export"><i class="download icon"></i>Export selected to ABA</button>
<button class="ui small basic primary labeled icon button" type="submit" name="action" value="ExportXero"><i class="download icon"></i>Export selected for Xero</button> <button class="ui small basic primary labeled icon button" type="submit" name="action" value="ExportXero"><i class="download icon"></i>Export selected for Xero</button>

View File

@ -1,5 +1,5 @@
# Society Self-Service # Society Self-Service
# Copyright © 2018–2020 Yingtong Li (RunasSudo) # Copyright © 2018–2021 Yingtong Li (RunasSudo)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -680,33 +680,39 @@ def claim_processing(request):
claims = [c for c in claims if request.POST.get('claim_{}'.format(c.id), False)] claims = [c for c in claims if request.POST.get('claim_{}'.format(c.id), False)]
claims.sort(key=lambda c: '{}/{}{}/{}'.format(c.payee_name.strip(), c.payee_bsb.strip()[:3], c.payee_bsb.strip()[-3:], c.payee_account.strip())) claims.sort(key=lambda c: '{}/{}{}/{}'.format(c.payee_name.strip(), c.payee_bsb.strip()[:3], c.payee_bsb.strip()[-3:], c.payee_account.strip()))
aba_file = io.BytesIO() try:
aba_file = io.BytesIO()
aba.write_descriptive(aba_file, bank_name=settings.ABA_BANK_NAME, user_name=settings.ABA_USER_NAME, bank_code=settings.ABA_BANK_CODE, description='Reimburse', date=timezone.localtime(timezone.now()))
aba.write_descriptive(aba_file, bank_name=settings.ABA_BANK_NAME, user_name=settings.ABA_USER_NAME, bank_code=settings.ABA_BANK_CODE, description='Reimburse', date=timezone.localtime(timezone.now()))
# CommBank requires only one entry per payee
num_records = 0 # CommBank requires only one entry per payee
for _, payee_claims in itertools.groupby(claims, key=lambda c: '{}/{}{}/{}'.format(c.payee_name.strip(), c.payee_bsb.strip()[:3], c.payee_bsb.strip()[-3:], c.payee_account.strip())): num_records = 0
payee_claims = list(payee_claims) for _, payee_claims in itertools.groupby(claims, key=lambda c: '{}/{}{}/{}'.format(c.payee_name.strip(), c.payee_bsb.strip()[:3], c.payee_bsb.strip()[-3:], c.payee_account.strip())):
aba.write_detail( payee_claims = list(payee_claims)
aba_file, aba.write_detail(
dest_bsb=payee_claims[0].payee_bsb, aba_file,
dest_account=payee_claims[0].payee_account, dest_bsb=payee_claims[0].payee_bsb,
cents=sum(c.get_total() for c in payee_claims)*100, dest_account=payee_claims[0].payee_account,
dest_name=payee_claims[0].payee_name[:32], cents=sum(c.get_total() for c in payee_claims)*100,
reference='RE{}'.format(' '.join(str(c.id) for c in payee_claims)), dest_name=payee_claims[0].payee_name[:32],
src_bsb=settings.ABA_SRC_BSB, reference='RE{}'.format(' '.join(str(c.id) for c in payee_claims)),
src_account=settings.ABA_SRC_ACC, src_bsb=settings.ABA_SRC_BSB,
src_name=settings.ABA_USER_NAME src_account=settings.ABA_SRC_ACC,
) src_name=settings.ABA_USER_NAME
num_records += 1 )
num_records += 1
aba.write_total(aba_file, credit_cents=sum(c.get_total() for c in claims)*100, num_detail_records=num_records)
aba_file.flush() aba.write_total(aba_file, credit_cents=sum(c.get_total() for c in claims)*100, num_detail_records=num_records)
aba_file.flush()
response = HttpResponse(aba_file.getvalue(), content_type='text/plain')
response['Content-Disposition'] = 'attachment; filename="claims.aba"' response = HttpResponse(aba_file.getvalue(), content_type='text/plain')
return response response['Content-Disposition'] = 'attachment; filename="claims.aba"'
return response
except aba.ABAException as ex:
return render(request, 'sstreasury/claim_processing.html', {
'claims': claims,
'error': ex
})
if request.POST['action'] == 'ExportXero': if request.POST['action'] == 'ExportXero':
#claims = models.ReimbursementClaim.objects.filter(state=models.ClaimState.APPROVED.value).all() #claims = models.ReimbursementClaim.objects.filter(state=models.ClaimState.APPROVED.value).all()