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
Copyright © 2018–2020 Yingtong Li (RunasSudo)
Copyright © 2018–2021 Yingtong Li (RunasSudo)
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
@ -23,6 +23,12 @@
{% block maincontent %}
<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">
<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>

View File

@ -1,5 +1,5 @@
# 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
# it under the terms of the GNU Affero General Public License as published by
@ -680,6 +680,7 @@ def claim_processing(request):
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()))
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()))
@ -707,6 +708,11 @@ def claim_processing(request):
response = HttpResponse(aba_file.getvalue(), content_type='text/plain')
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':
#claims = models.ReimbursementClaim.objects.filter(state=models.ClaimState.APPROVED.value).all()