diff --git a/src/backoffice/templates/includes/invoice_list_panel.html b/src/backoffice/templates/includes/invoice_list_panel.html
index c02e54aa..bd30532c 100644
--- a/src/backoffice/templates/includes/invoice_list_panel.html
+++ b/src/backoffice/templates/includes/invoice_list_panel.html
@@ -18,7 +18,7 @@
{{ invoice.id }} |
{% if invoice.order %}{{ invoice.order.user.username }} <{{ invoice.order.user.email }}>{% else %}{{ invoice.customorder.customer }}{% endif %} |
{{ invoice.created|date }} |
- {% if invoice.order %}{{ invoice.order.total }} DKK{% else %}{{ invoice.customorder.amount }}{% endif %} |
+ {% if invoice.order %}{{ invoice.order.total }}{% else %}{{ invoice.customorder.amount }}{% endif %} DKK |
{{ invoice.get_order }} |
{{ invoice.get_order.paid|truefalseicon }} {% if invoice.get_order.paid %}paid{% else %}unpaid{% endif %} |
diff --git a/src/backoffice/templates/invoice_list.html b/src/backoffice/templates/invoice_list.html
index 94a10bd6..36569f15 100644
--- a/src/backoffice/templates/invoice_list.html
+++ b/src/backoffice/templates/invoice_list.html
@@ -12,6 +12,9 @@ Invoices | {{ block.super }}
This table shows all invoices in the system.
+
+ Backoffice
+ CSV
{% include 'includes/invoice_list_panel.html' %}
{% endblock content %}
diff --git a/src/backoffice/urls.py b/src/backoffice/urls.py
index 7e258059..9772adb5 100644
--- a/src/backoffice/urls.py
+++ b/src/backoffice/urls.py
@@ -57,6 +57,7 @@ from .views import (
FacilityTypeListView,
FacilityTypeUpdateView,
FacilityUpdateView,
+ InvoiceListCSVView,
InvoiceListView,
IrcOverView,
MerchandiseOrdersView,
@@ -670,6 +671,11 @@ urlpatterns = [
include(
[
path("", InvoiceListView.as_view(), name="invoice_list"),
+ path(
+ "csv/",
+ InvoiceListCSVView.as_view(),
+ name="invoice_list_csv",
+ ),
]
),
),
diff --git a/src/backoffice/views/economy.py b/src/backoffice/views/economy.py
index 86d64e9d..3690d9ef 100644
--- a/src/backoffice/views/economy.py
+++ b/src/backoffice/views/economy.py
@@ -1,3 +1,4 @@
+import csv
import logging
import os
@@ -6,6 +7,7 @@ from django.contrib import messages
from django.contrib.auth.models import User
from django.core.files import File
from django.db.models import Count, Q, Sum
+from django.http import HttpResponse
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.utils import timezone
@@ -451,3 +453,30 @@ class RevenueDetailView(CampViewMixin, EconomyTeamPermissionMixin, UpdateView):
class InvoiceListView(CampViewMixin, EconomyTeamPermissionMixin, ListView):
model = Invoice
template_name = "invoice_list.html"
+
+
+class InvoiceListCSVView(CampViewMixin, EconomyTeamPermissionMixin, ListView):
+ """
+ CSV export of invoices for bookkeeping stuff
+ """
+
+ def get(self, request, *args, **kwargs):
+ response = HttpResponse(content_type="text/csv")
+ response[
+ "Content-Disposition"
+ ] = f'attachment; filename="bornhack-infoices-{timezone.now()}.csv"'
+ writer = csv.writer(response)
+ writer.writerow(["invoice", "invoice_date", "amount_dkk", "order", "paid"])
+ for invoice in Invoice.objects.all():
+ writer.writerow(
+ [
+ invoice.id,
+ invoice.created.date(),
+ invoice.order.total
+ if invoice.order
+ else invoice.customorder.amount,
+ invoice.get_order,
+ invoice.get_order.paid,
+ ]
+ )
+ return response
|