8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-09 03:16:25 +00:00

API support for app cotisations

This commit is contained in:
Maël Kervella 2018-04-21 22:36:10 +00:00
parent 6562f32ebf
commit 98dc4205be
3 changed files with 137 additions and 0 deletions

View file

@ -23,6 +23,15 @@ Serializers for the API app
""" """
from rest_framework import serializers from rest_framework import serializers
from cotisations.models import (
Facture,
Vente,
Article,
Banque,
Paiement,
Cotisation
)
from users.models import ( from users.models import (
User, User,
Club, Club,
@ -49,6 +58,73 @@ from machines.models import (
Ipv6List 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): class UserSerializer(serializers.HyperlinkedModelSerializer):
access = serializers.BooleanField(source='has_access') access = serializers.BooleanField(source='has_access')

View file

@ -30,6 +30,14 @@ from rest_framework.routers import DefaultRouter
from . import views from . import views
router = DefaultRouter() 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'users', views.UserViewSet)
router.register(r'clubs', views.ClubViewSet) router.register(r'clubs', views.ClubViewSet)
router.register(r'adherents', views.AdherentViewSet) router.register(r'adherents', views.AdherentViewSet)

View file

@ -33,6 +33,15 @@ from rest_framework.authtoken.models import Token
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import viewsets, status from rest_framework import viewsets, status
from cotisations.models import (
Facture,
Vente,
Article,
Banque,
Paiement,
Cotisation
)
from users.models import ( from users.models import (
User, User,
Club, Club,
@ -60,6 +69,14 @@ from machines.models import (
) )
from .serializers import ( from .serializers import (
# COTISATION APP
FactureSerializer,
VenteSerializer,
ArticleSerializer,
BanqueSerializer,
PaiementSerializer,
CotisationSerializer,
# USER APP
UserSerializer, UserSerializer,
ClubSerializer, ClubSerializer,
AdherentSerializer, 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): class UserViewSet(viewsets.ReadOnlyModelViewSet):
queryset = User.objects.all() queryset = User.objects.all()
serializer_class = UserSerializer serializer_class = UserSerializer