2021-06-14 19:45:36 +00:00
|
|
|
# Copyright (C) 2018-2021 by BDE ENS Paris-Saclay
|
2020-03-22 15:04:09 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
from django_filters.rest_framework import DjangoFilterBackend
|
2022-03-10 15:11:01 +00:00
|
|
|
|
|
|
|
from api.filters import RegexSafeSearchFilter
|
2020-03-22 15:04:09 +00:00
|
|
|
from api.viewsets import ReadProtectedModelViewSet
|
|
|
|
|
2020-04-22 01:26:45 +00:00
|
|
|
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-12-23 13:54:21 +00:00
|
|
|
queryset = Invoice.objects.order_by('id')
|
2020-03-22 15:04:09 +00:00
|
|
|
serializer_class = InvoiceSerializer
|
2022-03-10 15:11:01 +00:00
|
|
|
filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
|
2020-12-22 11:53:35 +00:00
|
|
|
filterset_fields = ['bde', 'object', 'description', 'name', 'address', 'date', 'acquitted', 'locked', ]
|
|
|
|
search_fields = ['$object', '$description', '$name', '$address', ]
|
2020-03-22 15:04:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
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-12-23 13:54:21 +00:00
|
|
|
queryset = Product.objects.order_by('invoice_id', 'id')
|
2020-03-22 15:04:09 +00:00
|
|
|
serializer_class = ProductSerializer
|
2022-03-10 15:11:01 +00:00
|
|
|
filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
|
2020-12-22 11:53:35 +00:00
|
|
|
filterset_fields = ['invoice', 'designation', 'quantity', 'amount', ]
|
|
|
|
search_fields = ['$designation', '$invoice__object', ]
|
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-12-23 13:54:21 +00:00
|
|
|
queryset = RemittanceType.objects.order_by('id')
|
2020-03-24 16:06:50 +00:00
|
|
|
serializer_class = RemittanceTypeSerializer
|
2022-03-10 15:11:01 +00:00
|
|
|
filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
|
2020-12-22 11:53:35 +00:00
|
|
|
filterset_fields = ['note', ]
|
|
|
|
search_fields = ['$note__special_type', ]
|
2020-03-24 16:06:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
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-12-23 13:54:21 +00:00
|
|
|
queryset = Remittance.objects.order_by('id')
|
2020-03-24 16:06:50 +00:00
|
|
|
serializer_class = RemittanceSerializer
|
2022-03-10 15:11:01 +00:00
|
|
|
filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
|
2020-12-23 13:54:21 +00:00
|
|
|
filterset_fields = ['date', 'remittance_type', 'comment', 'closed', 'transaction_proxies__transaction', ]
|
2020-12-22 11:53:35 +00:00
|
|
|
search_fields = ['$remittance_type__note__special_type', '$comment', ]
|
2020-04-22 01:26:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
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-12-23 13:54:21 +00:00
|
|
|
queryset = SogeCredit.objects.order_by('id')
|
2020-04-22 01:26:45 +00:00
|
|
|
serializer_class = SogeCreditSerializer
|
2022-03-10 15:11:01 +00:00
|
|
|
filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
|
2020-12-22 11:53:35 +00:00
|
|
|
filterset_fields = ['user', 'user__last_name', 'user__first_name', 'user__email', 'user__note__alias__name',
|
|
|
|
'user__note__alias__normalized_name', 'transactions', 'credit_transaction', ]
|
|
|
|
search_fields = ['$user__last_name', '$user__first_name', '$user__email', '$user__note__alias__name',
|
|
|
|
'$user__note__alias__normalized_name', ]
|