From 8adc700005379f4ce997bff22303a84abdd9d995 Mon Sep 17 00:00:00 2001
From: Laetitia
-
++
@@ -199,11 +201,5 @@ el.innerHTML = total_price; }) }); - - - if( '{{ phone_required }}' === 'True') { - document.getElementById('phone').required = true - } - {% endblock %} diff --git a/la_chariotte/order/views/grouped_order.py b/la_chariotte/order/views/grouped_order.py index ff77335..1ec6e29 100644 --- a/la_chariotte/order/views/grouped_order.py +++ b/la_chariotte/order/views/grouped_order.py @@ -30,8 +30,8 @@ class IndexView(LoginRequiredMixin, generic.ListView): # Get the 5 most recent old grouped orders old = grouped_orders.filter(delivery_date__lt=today).order_by("-delivery_date")[ - :5 - ] + :5 + ] # Get grouped orders that have crossed their ordering deadline # but the delivery date is still to come. @@ -82,7 +82,7 @@ class GroupedOrderEventView(generic.DetailView): description += "Heure de livraison : " + self.object.delivery_slot + "\n" if self.object.description: description += ( - "Note de l'organisateur.ice : " + "\n" + self.object.description + "Note de l'organisateur.ice : " + "\n" + self.object.description ) event.add("description", vText(description)) diff --git a/la_chariotte/tests/test_order_views_grouped_order.py b/la_chariotte/tests/test_order_views_grouped_order.py index cfce0c4..3d04f38 100644 --- a/la_chariotte/tests/test_order_views_grouped_order.py +++ b/la_chariotte/tests/test_order_views_grouped_order.py @@ -662,6 +662,36 @@ class TestGroupedOrderDetailView: assert order.price == 4 assert item.get_remaining_nb() == 16 + def test_phone_not_required_display(self, client, other_user): + """a user orders something without entering phone when it is required""" + grouped_order = create_grouped_order( + days_before_delivery_date=5, + days_before_deadline=2, + name="gr order test", + orga_user=other_user, + ) + assert grouped_order.phone_mandatory == True + item = models.Item.objects.create( + name="test item 1", grouped_order=grouped_order, price=1, max_limit=2 + ) + detail_url = reverse( + "order:grouped_order_detail", + kwargs={ + "code": grouped_order.code, + }, + ) + response = client.get(detail_url) + assert response.status_code == 200 + assert "gr order test" in response.content.decode() + assert ( + "Numéro de téléphone (facultatif)" not in response.content.decode() + ) + grouped_order.phone_mandatory = False + grouped_order.save() + response = client.get(detail_url) + assert "gr order test" in response.content.decode() + assert "Numéro de téléphone (facultatif)" in response.content.decode() + class TestGroupedOrderOverview: def test_get_overview(self, client_log): diff --git a/la_chariotte/tests/utils.py b/la_chariotte/tests/utils.py index b7cc913..7308c0f 100644 --- a/la_chariotte/tests/utils.py +++ b/la_chariotte/tests/utils.py @@ -9,12 +9,20 @@ pytestmark = pytest.mark.django_db def create_grouped_order( - days_before_delivery_date, days_before_deadline, name, orga_user + days_before_delivery_date, + days_before_deadline, + name, + orga_user, + phone_mandatory=True, ): date = timezone.now().date() + datetime.timedelta(days=days_before_delivery_date) deadline = timezone.now() + datetime.timedelta(days=days_before_deadline) grouped_order = models.GroupedOrder.objects.create( - name=name, orga=orga_user, delivery_date=date, deadline=deadline + name=name, + orga=orga_user, + delivery_date=date, + deadline=deadline, + phone_mandatory=phone_mandatory, ) grouped_order.create_code_from_pk() grouped_order.save()