separate last name and first name fields in csv export

This commit is contained in:
Laetitia Getti 2023-08-28 14:00:09 +02:00 committed by Laetitia Getti
parent 064a3a8c74
commit 947eded96f
2 changed files with 15 additions and 9 deletions

View file

@ -1448,6 +1448,7 @@ class TestExportGroupedOrderToCSVView:
body = list(csv_reader)
assert body == [
[
"",
"",
"test item",
"test item 2",
@ -1455,9 +1456,10 @@ class TestExportGroupedOrderToCSVView:
"Mail",
"Téléphone",
],
["Prix unitaire TTC (€)", "2,00", "9,00"],
["bob alescargot", "1", "0", "2,00", "bob2@escargot.fr", "'000"],
["bobby alescargot", "0", "1", "9,00", "bob3@escargot.fr", "'000"],
["bob lescargot", "3", "2", "24,00", "bob@escargot.fr", "'000"],
["TOTAL", "4", "3", "35,00"],
["", "Prix unitaire TTC (€)", "2,00", "9,00"],
["Nom", "Prénom"],
["alescargot", "bob", "1", "0", "2,00", "bob2@escargot.fr", "'000"],
["alescargot", "bobby", "0", "1", "9,00", "bob3@escargot.fr", "'000"],
["lescargot", "bob", "3", "2", "24,00", "bob@escargot.fr", "'000"],
["", "TOTAL", "4", "3", "35,00"],
]

View file

@ -322,7 +322,7 @@ class ExportGroupedOrderToCSVView(GroupedOrderExportView):
writer = csv.writer(response)
# write headers rows
row = [""]
row = ["", ""]
for item in context["items"]:
row.append(item.name)
row.append("Prix de la commande")
@ -330,14 +330,18 @@ class ExportGroupedOrderToCSVView(GroupedOrderExportView):
row.append("Téléphone")
writer.writerow(row)
row = ["Prix unitaire TTC (€)"]
row = ["", "Prix unitaire TTC (€)"]
for item in context["items"]:
row.append(str(item.price).replace(".", ","))
writer.writerow(row)
row = ["Nom", "Prénom"]
writer.writerow(row)
# write ordered values rows
for order, ordered_items in context["orders_dict"].items():
row = [order.author]
row = [order.author.last_name]
row.append(order.author.first_name)
for ordered_nb in ordered_items:
row.append(ordered_nb)
row.append(str(order.price).replace(".", ","))
@ -346,7 +350,7 @@ class ExportGroupedOrderToCSVView(GroupedOrderExportView):
writer.writerow(row)
# write total row
row = ["TOTAL"]
row = ["", "TOTAL"]
for item in context["items"]:
row.append(item.ordered_nb)
row.append(str(context["object"].total_price).replace(".", ","))