Export reimbursement claim receipts
This commit is contained in:
parent
dbe1eb988c
commit
ecfa4bdc2b
@ -37,6 +37,7 @@ import functools
|
||||
import io
|
||||
import itertools
|
||||
import json
|
||||
import zipfile
|
||||
|
||||
# HELPER DECORATORS
|
||||
|
||||
@ -663,14 +664,24 @@ def claim_processing(request):
|
||||
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)]
|
||||
|
||||
csv_file = io.StringIO()
|
||||
csv_writer = xero.new_writer(csv_file)
|
||||
|
||||
for claim in claims:
|
||||
xero.write_claim(csv_writer, claim)
|
||||
|
||||
response = HttpResponse(csv_file.getvalue(), content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename="claims.csv"'
|
||||
# Export CSV
|
||||
with io.StringIO() as csv_file:
|
||||
csv_writer = xero.new_writer(csv_file)
|
||||
for claim in claims:
|
||||
xero.write_claim(csv_writer, claim)
|
||||
|
||||
# Export resources to ZIP
|
||||
with io.BytesIO() as zip_file_bytes:
|
||||
with zipfile.ZipFile(zip_file_bytes, 'w') as zip_file:
|
||||
zip_file.writestr('claims.csv', csv_file.getvalue())
|
||||
|
||||
for claim in claims:
|
||||
for claim_receipt in claim.claimreceipt_set.all():
|
||||
with claim_receipt.uploaded_file.open() as f:
|
||||
zip_file.writestr('RE-{}/{}'.format(claim.id, claim_receipt.uploaded_file.name.split('/')[-1]), f.read())
|
||||
|
||||
response = HttpResponse(zip_file_bytes.getvalue(), content_type='application/zip')
|
||||
response['Content-Disposition'] = 'attachment; filename="claims.zip"'
|
||||
return response
|
||||
|
||||
if request.POST['action'] == 'Pay':
|
||||
|
@ -36,6 +36,7 @@ def write_claim(writer, claim):
|
||||
'Description': item['Description'],
|
||||
'*Quantity': str(item['Units']),
|
||||
'*UnitAmount': str(item['Unit price']),
|
||||
'*AccountCode': '850', # Suspense
|
||||
#'*AccountCode': '850', # Suspense
|
||||
'*AccountCode': 'EVT-E',
|
||||
'*TaxType': 'GST Free Expenses' if item['GST-free'] else 'GST on Expenses',
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user