1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-24 08:22:22 +00:00
nk20/apps/treasury/api/views.py

65 lines
2.3 KiB
Python
Raw Normal View History

2020-03-22 15:04:09 +00:00
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter
from api.viewsets import ReadProtectedModelViewSet
from .serializers import InvoiceSerializer, ProductSerializer, RemittanceTypeSerializer, RemittanceSerializer,\
SogeCreditSerializer
from ..models import Invoice, Product, RemittanceType, Remittance, SogeCredit
2020-03-22 15:04:09 +00:00
class InvoiceViewSet(ReadProtectedModelViewSet):
"""
REST API View set.
The djangorestframework plugin will get all `Invoice` objects, serialize it to JSON with the given serializer,
then render it on /api/treasury/invoice/
"""
2020-09-04 13:53:00 +00:00
queryset = Invoice.objects.order_by("id").all()
2020-03-22 15:04:09 +00:00
serializer_class = InvoiceSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ['bde', ]
class ProductViewSet(ReadProtectedModelViewSet):
"""
REST API View set.
The djangorestframework plugin will get all `Product` objects, serialize it to JSON with the given serializer,
then render it on /api/treasury/product/
"""
2020-09-04 13:53:00 +00:00
queryset = Product.objects.order_by("invoice_id", "id").all()
2020-03-22 15:04:09 +00:00
serializer_class = ProductSerializer
filter_backends = [SearchFilter]
search_fields = ['$designation', ]
2020-03-24 16:06:50 +00:00
class RemittanceTypeViewSet(ReadProtectedModelViewSet):
"""
REST API View set.
The djangorestframework plugin will get all `RemittanceType` objects, serialize it to JSON with the given serializer
then render it on /api/treasury/remittance_type/
"""
2020-09-04 13:53:00 +00:00
queryset = RemittanceType.objects.order_by("id")
2020-03-24 16:06:50 +00:00
serializer_class = RemittanceTypeSerializer
class RemittanceViewSet(ReadProtectedModelViewSet):
"""
REST API View set.
The djangorestframework plugin will get all `Remittance` objects, serialize it to JSON with the given serializer,
then render it on /api/treasury/remittance/
"""
2020-09-04 13:53:00 +00:00
queryset = Remittance.objects.order_by("id")
2020-03-24 16:06:50 +00:00
serializer_class = RemittanceSerializer
class SogeCreditViewSet(ReadProtectedModelViewSet):
"""
REST API View set.
The djangorestframework plugin will get all `SogeCredit` objects, serialize it to JSON with the given serializer,
then render it on /api/treasury/soge_credit/
"""
2020-09-04 13:53:00 +00:00
queryset = SogeCredit.objects.order_by("id")
serializer_class = SogeCreditSerializer