diff --git a/api/serializers.py b/api/serializers.py index 3e111920..ec4d0689 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -795,7 +795,7 @@ class UserSerializer(NamespacedHMSerializer): "access", "end_access", "uid", - "class_name", + "class_type", "api_url", ) extra_kwargs = {"shell": {"view_name": "shell-detail"}} diff --git a/cotisations/models.py b/cotisations/models.py index 1a593dad..215fcdb5 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -775,7 +775,7 @@ class Article(RevMixin, AclMixin, models.Model): target_user: The user to sell articles """ if target_user is None: - objects_pool = cls.objects.filter(Q(type_user="All")) + objects_pool = cls.objects.all() elif target_user.is_class_club: objects_pool = cls.objects.filter(Q(type_user="All") | Q(type_user="Club")) else: diff --git a/cotisations/views.py b/cotisations/views.py index c39aa815..cc80e22d 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -102,7 +102,7 @@ def new_facture(request, user, userid): invoice = Facture(user=user) # The template needs the list of articles (for the JS part) article_list = Article.objects.filter( - Q(type_user="All") | Q(type_user=request.user.class_name) + Q(type_user="All") | Q(type_user=user.class_type) ) # Building the invoice form and the article formset invoice_form = FactureForm( @@ -184,9 +184,7 @@ def new_cost_estimate(request): point of view. """ # The template needs the list of articles (for the JS part) - articles = Article.objects.filter( - Q(type_user="All") | Q(type_user=request.user.class_name) - ) + articles = Article.objects.all() # Building the invocie form and the article formset cost_estimate_form = CostEstimateForm(request.POST or None) @@ -241,9 +239,7 @@ def new_custom_invoice(request): point of view. """ # The template needs the list of articles (for the JS part) - articles = Article.objects.filter( - Q(type_user="All") | Q(type_user=request.user.class_name) - ) + articles = Article.objects.all() # Building the invocie form and the article formset invoice_form = CustomInvoiceForm(request.POST or None) diff --git a/users/models.py b/users/models.py index ba15354b..3d21548a 100755 --- a/users/models.py +++ b/users/models.py @@ -283,8 +283,18 @@ class User( return str(self.emailaddress_set.get(local_part=self.pseudo.lower())) @cached_property - def class_name(self): - """Renvoie si il s'agit d'un adhérent ou d'un club""" + def class_type(self): + """Returns the type of that user; returns database keyname""" + if hasattr(self, "adherent"): + return "Adherent" + elif hasattr(self, "club"): + return "Club" + else: + raise NotImplementedError(_("Unknown type.")) + + @cached_property + def class_display(self): + """Returns the typename of that user to display for user interface""" if hasattr(self, "adherent"): return _("Member") elif hasattr(self, "club"):