Combine entries for same payee within ABA file
This commit is contained in:
parent
bbd775789f
commit
74d4c7b333
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user