diff --git a/counter/models.py b/counter/models.py index 3640c3f5..18215856 100644 --- a/counter/models.py +++ b/counter/models.py @@ -652,13 +652,12 @@ class Counter(models.Model): )["total"] def customer_is_barman(self, customer: Customer | User) -> bool: - """Check if current counter is a `bar` and that the customer is on the barmen_list + """Check if this counter is a `bar` and if the customer is currently logged in. + This is useful to compute special prices.""" - This is useful to compute special prices""" - if isinstance(customer, Customer): - customer: User = customer.user - - return self.type == "BAR" and customer in self.barmen_list + # Customer and User are two different tables, + # but they share the same primary key + return self.type == "BAR" and any(b.pk == customer.pk for b in self.barmen_list) class RefillingQuerySet(models.QuerySet): diff --git a/counter/views/click.py b/counter/views/click.py index c6bafa57..9542b467 100644 --- a/counter/views/click.py +++ b/counter/views/click.py @@ -417,7 +417,7 @@ class RefillingCreateView(FormView): def get_template_data( cls, customer: Customer, *, form_instance: form_class | None = None ) -> FormFragmentTemplateData[form_class]: - return FormFragmentTemplateData[cls.form_class]( + return FormFragmentTemplateData( form=form_instance if form_instance else cls.form_class(), template=cls.template_name, context={ diff --git a/counter/views/student_card.py b/counter/views/student_card.py index 952f65eb..f916260b 100644 --- a/counter/views/student_card.py +++ b/counter/views/student_card.py @@ -73,7 +73,7 @@ class StudentCardFormView(FormView): cls, customer: Customer, *, form_instance: form_class | None = None ) -> FormFragmentTemplateData[form_class]: """Get necessary data to pre-render the fragment""" - return FormFragmentTemplateData[cls.form_class]( + return FormFragmentTemplateData( form=form_instance if form_instance else cls.form_class(), template=cls.template_name, context={