summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2020-06-01 22:55:51 +1000
committerYingtong Li <runassudo@yingtongli.me>2020-06-01 23:07:22 +1000
commit74d4c7b333edf8dc40e9af97ab71523ca8e169f2 (patch)
tree0992a402364e4ec616d5f00ec655f1fc83af3fb6
parentbbd775789f038f07446ca0f9d0f82ce7d75620ad (diff)
Combine entries for same payee within ABA file
-rw-r--r--sstreasury/views.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/sstreasury/views.py b/sstreasury/views.py
index 689a451..f2de186 100644
--- a/sstreasury/views.py
+++ b/sstreasury/views.py
@@ -654,15 +654,30 @@ def claim_processing(request):
if request.POST['action'] == 'Export':
claims = models.ReimbursementClaim.objects.filter(state=models.ClaimState.APPROVED.value).all()
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()))
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.now())
- for claim in claims:
- aba.write_detail(aba_file, dest_bsb=claim.payee_bsb, dest_account=claim.payee_account, cents=claim.get_total()*100, dest_name=claim.payee_name, reference='RE-{}'.format(claim.id), src_bsb=settings.ABA_SRC_BSB, src_account=settings.ABA_SRC_ACC, src_name=settings.ABA_USER_NAME)
+ # CommBank requires only one entry per payee
+ 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())):
+ payee_claims = list(payee_claims)
+ aba.write_detail(
+ aba_file,
+ 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,
+ reference='RE{}'.format(' '.join(str(c.id) for c in payee_claims)),
+ src_bsb=settings.ABA_SRC_BSB,
+ src_account=settings.ABA_SRC_ACC,
+ src_name=settings.ABA_USER_NAME
+ )
+ num_records += 1
- aba.write_total(aba_file, credit_cents=sum(c.get_total() for c in claims)*100, num_detail_records=len(claims))
+ 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')
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.