Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 98dc4205 authored by Maël Kervella's avatar Maël Kervella

API support for app cotisations

parent 6562f32e
......@@ -23,6 +23,15 @@ Serializers for the API app
"""
from rest_framework import serializers
from cotisations.models import (
Facture,
Vente,
Article,
Banque,
Paiement,
Cotisation
)
from users.models import (
User,
Club,
......@@ -49,6 +58,73 @@ from machines.models import (
Ipv6List
)
# COTISATION APP
class FactureSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Facture
fields = ('user', 'paiement', 'banque', 'cheque', 'date', 'valid',
'control', 'prix_total', 'name', 'api_url')
extra_kwargs = {
'user': {'view_name': 'api:user-detail'},
'paiement': {'view_name': 'api:paiement-detail'},
'banque': {'view_name': 'api:banque-detail'},
'api_url': {'view_name': 'api:facture-detail'}
}
class VenteSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Vente
fields = ('facture', 'number', 'name', 'prix', 'duration',
'type_cotisation', 'prix_total', 'api_url')
extra_kwargs = {
'facture': {'view_name': 'api:facture-detail'},
'api_url': {'view_name': 'api:vente-detail'}
}
class ArticleSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Article
fields = ('name', 'prix', 'duration', 'type_user',
'type_cotisation', 'api_url')
extra_kwargs = {
'api_url': {'view_name': 'api:article-detail'}
}
class BanqueSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Banque
fields = ('name', 'api_url')
extra_kwargs = {
'api_url': {'view_name': 'api:banque-detail'}
}
class PaiementSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Paiement
fields = ('moyen', 'type_paiement', 'api_url')
extra_kwargs = {
'api_url': {'view_name': 'api:paiement-detail'}
}
class CotisationSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Cotisation
fields = ('vente', 'type_cotisation', 'date_start', 'date_end',
'api_url')
extra_kwargs = {
'vente': {'view_name': 'api:vente-detail'},
'api_url': {'view_name': 'api:cotisation-detail'}
}
# USER APP
class UserSerializer(serializers.HyperlinkedModelSerializer):
access = serializers.BooleanField(source='has_access')
......
......@@ -30,6 +30,14 @@ from rest_framework.routers import DefaultRouter
from . import views
router = DefaultRouter()
# COTISATION APP
router.register(r'factures', views.FactureViewSet)
router.register(r'ventes', views.VenteViewSet)
router.register(r'articles', views.ArticleViewSet)
router.register(r'banques', views.BanqueViewSet)
router.register(r'paiements', views.PaiementViewSet)
router.register(r'cotisations', views.CotisationViewSet)
# USER APP
router.register(r'users', views.UserViewSet)
router.register(r'clubs', views.ClubViewSet)
router.register(r'adherents', views.AdherentViewSet)
......
......@@ -33,6 +33,15 @@ from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework import viewsets, status
from cotisations.models import (
Facture,
Vente,
Article,
Banque,
Paiement,
Cotisation
)
from users.models import (
User,
Club,
......@@ -60,6 +69,14 @@ from machines.models import (
)
from .serializers import (
# COTISATION APP
FactureSerializer,
VenteSerializer,
ArticleSerializer,
BanqueSerializer,
PaiementSerializer,
CotisationSerializer,
# USER APP
UserSerializer,
ClubSerializer,
AdherentSerializer,
......@@ -72,6 +89,42 @@ from .serializers import (
)
# COTISATION APP
class FactureViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Facture.objects.all()
serializer_class = FactureSerializer
class VenteViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Vente.objects.all()
serializer_class = VenteSerializer
class ArticleViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Article.objects.all()
serializer_class = ArticleSerializer
class BanqueViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Banque.objects.all()
serializer_class = BanqueSerializer
class PaiementViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Paiement.objects.all()
serializer_class = PaiementSerializer
class CotisationViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Cotisation.objects.all()
serializer_class = CotisationSerializer
# USER APP
class UserViewSet(viewsets.ReadOnlyModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment