Merge pull request #1227 from ae-utbm/sales-csv-header

fix: missing sales csv header row
This commit is contained in:
thomas girod
2025-11-07 15:39:42 +01:00
committed by GitHub
2 changed files with 49 additions and 36 deletions

View File

@@ -23,6 +23,7 @@
# #
import csv import csv
import itertools
from typing import Any from typing import Any
from django.conf import settings from django.conf import settings
@@ -37,7 +38,7 @@ from django.urls import reverse, reverse_lazy
from django.utils import timezone from django.utils import timezone
from django.utils.safestring import SafeString from django.utils.safestring import SafeString
from django.utils.timezone import now from django.utils.timezone import now
from django.utils.translation import gettext as _t from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, ListView, View from django.views.generic import DetailView, ListView, View
from django.views.generic.edit import CreateView, DeleteView, UpdateView from django.views.generic.edit import CreateView, DeleteView, UpdateView
@@ -487,40 +488,40 @@ class ClubSellingCSVView(ClubSellingView):
kwargs = self.get_context_data(**kwargs) kwargs = self.get_context_data(**kwargs)
# Use the StreamWriter class instead of request for streaming # Use the StreamWriter class instead of request for streaming
pseudo_buffer = self.StreamWriter() writer = csv.writer(self.StreamWriter())
writer = csv.writer(
pseudo_buffer, delimiter=";", lineterminator="\n", quoting=csv.QUOTE_ALL
)
writer.writerow([_t("Quantity"), kwargs["total_quantity"]]) first_rows = [
writer.writerow([_t("Total"), kwargs["total"]]) [gettext("Quantity"), kwargs["total_quantity"]],
writer.writerow([_t("Benefit"), kwargs["benefit"]]) [gettext("Total"), kwargs["total"]],
writer.writerow( [gettext("Benefit"), kwargs["benefit"]],
[ [
_t("Date"), gettext("Date"),
_t("Counter"), gettext("Counter"),
_t("Barman"), gettext("Barman"),
_t("Customer"), gettext("Customer"),
_t("Label"), gettext("Label"),
_t("Quantity"), gettext("Quantity"),
_t("Total"), gettext("Total"),
_t("Payment method"), gettext("Payment method"),
_t("Selling price"), gettext("Selling price"),
_t("Purchase price"), gettext("Purchase price"),
_t("Benefit"), gettext("Benefit"),
] ],
) ]
# Stream response # Stream response
response = StreamingHttpResponse( response = StreamingHttpResponse(
( itertools.chain(
writer.writerow(self.write_selling(selling)) (writer.writerow(r) for r in first_rows),
for selling in kwargs["result"] (
writer.writerow(self.write_selling(selling))
for selling in kwargs["result"]
),
), ),
content_type="text/csv", content_type="text/csv",
) )
name = _("Sellings") + "_" + self.object.name + ".csv" name = f"{gettext('Sellings')}_{self.object.name}.csv"
response["Content-Disposition"] = "filename=" + name response["Content-Disposition"] = f"attachment; filename={name}"
return response return response

View File

@@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-11-04 12:43+0100\n" "POT-Creation-Date: 2025-11-07 14:50+0100\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n" "Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@@ -146,7 +146,7 @@ msgstr "Date de début"
msgid "End date" msgid "End date"
msgstr "Date de fin" msgstr "Date de fin"
#: club/forms.py club/templates/club/club_sellings.jinja #: club/forms.py club/templates/club/club_sellings.jinja club/views.py
#: core/templates/core/user_account_detail.jinja #: core/templates/core/user_account_detail.jinja
#: counter/templates/counter/cash_summary_list.jinja counter/views/mixins.py #: counter/templates/counter/cash_summary_list.jinja counter/views/mixins.py
msgid "Counter" msgid "Counter"
@@ -409,7 +409,7 @@ msgstr "Total : "
msgid "Benefit: " msgid "Benefit: "
msgstr "Bénéfice : " msgstr "Bénéfice : "
#: club/templates/club/club_sellings.jinja #: club/templates/club/club_sellings.jinja club/views.py
#: core/templates/core/user_account_detail.jinja #: core/templates/core/user_account_detail.jinja
#: counter/templates/counter/cash_summary_list.jinja #: counter/templates/counter/cash_summary_list.jinja
#: counter/templates/counter/last_ops.jinja #: counter/templates/counter/last_ops.jinja
@@ -419,34 +419,34 @@ msgstr "Bénéfice : "
msgid "Date" msgid "Date"
msgstr "Date" msgstr "Date"
#: club/templates/club/club_sellings.jinja #: club/templates/club/club_sellings.jinja club/views.py
#: core/templates/core/user_account_detail.jinja #: core/templates/core/user_account_detail.jinja
#: counter/templates/counter/last_ops.jinja #: counter/templates/counter/last_ops.jinja
msgid "Barman" msgid "Barman"
msgstr "Barman" msgstr "Barman"
#: club/templates/club/club_sellings.jinja #: club/templates/club/club_sellings.jinja club/views.py
#: counter/templates/counter/counter_click.jinja #: counter/templates/counter/counter_click.jinja
#: counter/templates/counter/last_ops.jinja #: counter/templates/counter/last_ops.jinja
#: counter/templates/counter/refilling_list.jinja #: counter/templates/counter/refilling_list.jinja
msgid "Customer" msgid "Customer"
msgstr "Client" msgstr "Client"
#: club/templates/club/club_sellings.jinja #: club/templates/club/club_sellings.jinja club/views.py
#: core/templates/core/user_account_detail.jinja #: core/templates/core/user_account_detail.jinja
#: counter/templates/counter/last_ops.jinja #: counter/templates/counter/last_ops.jinja
#: rootplace/templates/rootplace/logs.jinja #: rootplace/templates/rootplace/logs.jinja
msgid "Label" msgid "Label"
msgstr "Étiquette" msgstr "Étiquette"
#: club/templates/club/club_sellings.jinja #: club/templates/club/club_sellings.jinja club/views.py
#: core/templates/core/user_account_detail.jinja #: core/templates/core/user_account_detail.jinja
#: core/templates/core/user_stats.jinja #: core/templates/core/user_stats.jinja
#: counter/templates/counter/last_ops.jinja #: counter/templates/counter/last_ops.jinja
msgid "Quantity" msgid "Quantity"
msgstr "Quantité" msgstr "Quantité"
#: club/templates/club/club_sellings.jinja #: club/templates/club/club_sellings.jinja club/views.py
#: core/templates/core/user_account.jinja #: core/templates/core/user_account.jinja
#: core/templates/core/user_account_detail.jinja #: core/templates/core/user_account_detail.jinja
#: counter/templates/counter/cash_summary_list.jinja #: counter/templates/counter/cash_summary_list.jinja
@@ -456,7 +456,7 @@ msgstr "Quantité"
msgid "Total" msgid "Total"
msgstr "Total" msgstr "Total"
#: club/templates/club/club_sellings.jinja #: club/templates/club/club_sellings.jinja club/views.py
#: core/templates/core/user_account_detail.jinja #: core/templates/core/user_account_detail.jinja
#: core/templates/core/user_detail.jinja #: core/templates/core/user_detail.jinja
#: counter/templates/counter/last_ops.jinja #: counter/templates/counter/last_ops.jinja
@@ -699,6 +699,18 @@ msgstr "Vous êtes maintenant membre de ce club."
msgid "%(user)s has been added to club." msgid "%(user)s has been added to club."
msgstr "%(user)s a été ajouté au club." msgstr "%(user)s a été ajouté au club."
#: club/views.py
msgid "Benefit"
msgstr "Bénéfice"
#: club/views.py
msgid "Selling price"
msgstr "Prix de vente"
#: club/views.py
msgid "Purchase price"
msgstr "Prix d'achat"
#: com/forms.py #: com/forms.py
msgid "Format: 16:9 | Resolution: 1920x1080" msgid "Format: 16:9 | Resolution: 1920x1080"
msgstr "Format : 16:9 | Résolution : 1920x1080" msgstr "Format : 16:9 | Résolution : 1920x1080"