Display ABA errors on export page
This commit is contained in:
parent
44ba18d22e
commit
6be52fb718
@ -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>
|
||||||
|
@ -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
|
# CommBank requires only one entry per payee
|
||||||
num_records = 0
|
num_records = 0
|
||||||
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())):
|
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())):
|
||||||
payee_claims = list(payee_claims)
|
payee_claims = list(payee_claims)
|
||||||
aba.write_detail(
|
aba.write_detail(
|
||||||
aba_file,
|
aba_file,
|
||||||
dest_bsb=payee_claims[0].payee_bsb,
|
dest_bsb=payee_claims[0].payee_bsb,
|
||||||
dest_account=payee_claims[0].payee_account,
|
dest_account=payee_claims[0].payee_account,
|
||||||
cents=sum(c.get_total() for c in payee_claims)*100,
|
cents=sum(c.get_total() for c in payee_claims)*100,
|
||||||
dest_name=payee_claims[0].payee_name[:32],
|
dest_name=payee_claims[0].payee_name[:32],
|
||||||
reference='RE{}'.format(' '.join(str(c.id) for c in payee_claims)),
|
reference='RE{}'.format(' '.join(str(c.id) for c in payee_claims)),
|
||||||
src_bsb=settings.ABA_SRC_BSB,
|
src_bsb=settings.ABA_SRC_BSB,
|
||||||
src_account=settings.ABA_SRC_ACC,
|
src_account=settings.ABA_SRC_ACC,
|
||||||
src_name=settings.ABA_USER_NAME
|
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.write_total(aba_file, credit_cents=sum(c.get_total() for c in claims)*100, num_detail_records=num_records)
|
||||||
aba_file.flush()
|
aba_file.flush()
|
||||||
|
|
||||||
response = HttpResponse(aba_file.getvalue(), content_type='text/plain')
|
response = HttpResponse(aba_file.getvalue(), content_type='text/plain')
|
||||||
response['Content-Disposition'] = 'attachment; filename="claims.aba"'
|
response['Content-Disposition'] = 'attachment; filename="claims.aba"'
|
||||||
return response
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user