summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2020-02-14 15:14:51 +1100
committerYingtong Li <runassudo@yingtongli.me>2020-02-14 15:22:23 +1100
commitecfa4bdc2bdbd8184d5dbef6e1fbb0ce0267e76e (patch)
tree47ebc9c098d6419ac5a43e3e4ae17c8594510664
parentdbe1eb988c7c61e4b481e29e435f11549429f345 (diff)
Export reimbursement claim receipts
-rw-r--r--sstreasury/views.py27
-rw-r--r--sstreasury/xero.py3
2 files changed, 21 insertions, 9 deletions
diff --git a/sstreasury/views.py b/sstreasury/views.py
index 63677bc..4add30e 100644
--- a/sstreasury/views.py
+++ b/sstreasury/views.py
@@ -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':
diff --git a/sstreasury/xero.py b/sstreasury/xero.py
index 16d3ef0..4700e46 100644
--- a/sstreasury/xero.py
+++ b/sstreasury/xero.py
@@ -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',
})
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.