mirror of
https://github.com/ae-utbm/sith.git
synced 2025-11-15 17:09:21 +00:00
test ClubSellingCSVView
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import csv
|
||||
import itertools
|
||||
|
||||
import pytest
|
||||
from django.test import Client
|
||||
from django.urls import reverse
|
||||
@@ -7,7 +10,7 @@ from club.forms import SellingsForm
|
||||
from club.models import Club
|
||||
from core.models import User
|
||||
from counter.baker_recipes import product_recipe, sale_recipe
|
||||
from counter.models import Counter, Customer, Product
|
||||
from counter.models import Counter, Customer, Product, Selling
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -40,3 +43,62 @@ def test_sales_form_counter_filter():
|
||||
form = SellingsForm(club)
|
||||
form_counters = list(form.fields["counters"].queryset)
|
||||
assert form_counters == [counters[1], counters[2], counters[0]]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_club_sales_csv(client: Client):
|
||||
client.force_login(baker.make(User, is_superuser=True))
|
||||
club = baker.make(Club)
|
||||
counter = baker.make(Counter, club=club)
|
||||
product = product_recipe.make(club=club, counters=[counter], purchase_price=0.5)
|
||||
customers = baker.make(Customer, amount=100, _quantity=2, _bulk_create=True)
|
||||
sales: list[Selling] = sale_recipe.make(
|
||||
club=club,
|
||||
counter=counter,
|
||||
quantity=2,
|
||||
unit_price=1.5,
|
||||
product=iter([product, product, None]),
|
||||
customer=itertools.cycle(customers),
|
||||
_quantity=3,
|
||||
)
|
||||
url = reverse("club:sellings_csv", kwargs={"club_id": club.id})
|
||||
response = client.post(url, data={"counters": [counter.id]})
|
||||
assert response.status_code == 200
|
||||
reader = csv.reader(s.decode() for s in response.streaming_content)
|
||||
data = list(reader)
|
||||
sale_rows = [
|
||||
[
|
||||
str(s.date),
|
||||
str(counter),
|
||||
str(s.seller),
|
||||
s.customer.user.get_display_name(),
|
||||
s.label,
|
||||
"2",
|
||||
"1.50",
|
||||
"3.00",
|
||||
"Compte utilisateur",
|
||||
]
|
||||
for s in sales[::-1]
|
||||
]
|
||||
sale_rows[2].extend(["0.50", "1.00"])
|
||||
sale_rows[1].extend(["0.50", "1.00"])
|
||||
sale_rows[0].extend(["", ""])
|
||||
assert data == [
|
||||
["Quantité", "6"],
|
||||
["Total", "9"],
|
||||
["Bénéfice", "1"],
|
||||
[
|
||||
"Date",
|
||||
"Comptoir",
|
||||
"Barman",
|
||||
"Client",
|
||||
"Étiquette",
|
||||
"Quantité",
|
||||
"Prix unitaire",
|
||||
"Total",
|
||||
"Méthode de paiement",
|
||||
"Prix d'achat",
|
||||
"Bénéfice",
|
||||
],
|
||||
*sale_rows,
|
||||
]
|
||||
|
||||
@@ -460,15 +460,15 @@ class ClubSellingCSVView(ClubSellingView):
|
||||
*row,
|
||||
selling.label,
|
||||
selling.quantity,
|
||||
selling.unit_price,
|
||||
selling.quantity * selling.unit_price,
|
||||
selling.get_payment_method_display(),
|
||||
]
|
||||
if selling.product:
|
||||
row.append(selling.product.selling_price)
|
||||
row.append(selling.product.purchase_price)
|
||||
row.append(selling.product.selling_price - selling.product.purchase_price)
|
||||
row.append(selling.unit_price - selling.product.purchase_price)
|
||||
else:
|
||||
row = [*row, "", "", ""]
|
||||
row = [*row, "", ""]
|
||||
return row
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
@@ -489,9 +489,9 @@ class ClubSellingCSVView(ClubSellingView):
|
||||
gettext("Customer"),
|
||||
gettext("Label"),
|
||||
gettext("Quantity"),
|
||||
gettext("Unit price"),
|
||||
gettext("Total"),
|
||||
gettext("Payment method"),
|
||||
gettext("Selling price"),
|
||||
gettext("Purchase price"),
|
||||
gettext("Benefit"),
|
||||
],
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2025-11-11 13:52+0100\n"
|
||||
"POT-Creation-Date: 2025-11-12 21:44+0100\n"
|
||||
"PO-Revision-Date: 2016-07-18\n"
|
||||
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
|
||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||
@@ -704,8 +704,8 @@ msgid "Benefit"
|
||||
msgstr "Bénéfice"
|
||||
|
||||
#: club/views.py
|
||||
msgid "Selling price"
|
||||
msgstr "Prix de vente"
|
||||
msgid "Unit price"
|
||||
msgstr "Prix unitaire"
|
||||
|
||||
#: club/views.py
|
||||
msgid "Purchase price"
|
||||
@@ -5666,12 +5666,3 @@ msgstr "Vous ne pouvez plus écrire de commentaires, la date est passée."
|
||||
#, python-format
|
||||
msgid "Maximum characters: %(max_length)s"
|
||||
msgstr "Nombre de caractères max: %(max_length)s"
|
||||
|
||||
#~ msgid "is viewable"
|
||||
#~ msgstr "profil visible"
|
||||
|
||||
#~ msgid "One month for free"
|
||||
#~ msgstr "Un mois gratuit"
|
||||
|
||||
#~ msgid "Two months for free"
|
||||
#~ msgstr "Deux mois gratuits"
|
||||
|
||||
Reference in New Issue
Block a user