diff --git a/counter/tests/test_counter.py b/counter/tests/test_counter.py index 69d2d8b0..b83fb4e6 100644 --- a/counter/tests/test_counter.py +++ b/counter/tests/test_counter.py @@ -405,7 +405,7 @@ class TestCounterClick(TestFullClickBase): self.assertRedirects(res, self.counter.get_absolute_url()) assert self.updated_amount(self.customer) == Decimal(8) - def test_click_alcool_unauthorized(self): + def test_click_alcohol_unauthorized(self): self.login_in_bar() for user in [self.underage_customer, self.banned_alcohol_customer]: @@ -423,6 +423,31 @@ class TestCounterClick(TestFullClickBase): assert self.updated_amount(user) == Decimal(7) + def test_click_no_alcohol_if_minor_barman(self): + """Test that no age restricted product can be sold if the barman is minor.""" + set_age(self.barmen, 17) + self.login_in_bar(self.barmen) + res = self.client.get( + reverse( + "counter:click", + kwargs={"counter_id": self.counter.id, "user_id": self.customer.id}, + ) + ) + assert res.status_code == 200 + messages = list(get_messages(res.wsgi_request)) + assert len(messages) == 1 + assert messages[0].level == DEFAULT_LEVELS["WARNING"] + assert messages[0].message == ( + "Un mineur est barman sur cet appareil, " + "vous ne pouvez donc pas vendre d'alcool actuellement." + ) + assert res.context_data["prices"] == [ + self.gift, + self.snack, + self.cons, + self.dcons, + ] + def test_click_unauthorized_customer(self): self.login_in_bar() diff --git a/counter/views/click.py b/counter/views/click.py index b3046e81..d89cad44 100644 --- a/counter/views/click.py +++ b/counter/views/click.py @@ -111,6 +111,17 @@ class CounterClick( return redirect(obj) # Redirect to counter self.prices = list(obj.get_prices_for(self.customer)) + if any(user.age < 18 for user in request.barmen): + filtered = [p for p in self.prices if p.product.limit_age < 18] + if len(filtered) != len(self.prices): + self.prices = filtered + messages.warning( + request, + _( + "A minor is barman on this on this device, " + "so you cannot currently sell alcohol." + ), + ) return super().dispatch(request, *args, **kwargs) diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index d595bbac..b1fc357d 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-10 13:16+0100\n" +"POT-Creation-Date: 2026-11-12 15:32+0100\n" "PO-Revision-Date: 2016-07-18\n" "Last-Translator: Maréchal \n" @@ -4339,6 +4339,13 @@ msgstr "Nombre de chèque" msgid "You cannot click users on this counter" msgstr "Vous ne pouvez pas cliquer des gens sur ce comptoir" +#: counter/views/click.py +msgid "" +"A minor is barman on this on this device, so you cannot currently sell " +"alcohol." +msgstr "" +"Un mineur est barman sur cet appareil, vous ne pouvez donc pas vendre d'alcool actuellement." + #: counter/views/eticket.py msgid "people(s)" msgstr "personne(s)"