Commit a42e081f authored by Hamza Dely's avatar Hamza Dely

[consos/serializers] TransactionSerializer utilise des champs dynamiques

parent 63d9df77
......@@ -47,7 +47,7 @@ class BoutonSerializer(serializers.ModelSerializer):
]
read_only_fields = ['id', 'actif']
class TransactionSerializer(serializers.ModelSerializer):
class TransactionSerializer(mixins.DynamicFieldsMixin, serializers.ModelSerializer):
"""
Sérialiseur pour les transactions
"""
......@@ -70,6 +70,7 @@ class TransactionSerializer(serializers.ModelSerializer):
'destinataire', 'emetteurs', 'destinataires', 'bouton',
]
read_only_fields = ['date', 'emetteur', 'destinataire']
default_empty = False
def create(self, validated_data):
params = {
......
......@@ -642,11 +642,9 @@ class TransactionViewSet(viewsets.GenericViewSet):
if not request.user.has_perm("consos.transaction_devalider"):
return Response({}, status=status.HTTP_403_FORBIDDEN)
valide = to_bool(request.query_params.get('valide', None))
if valide is None:
return Response({"detail" : "Paramètre 'valide' manquant"}, status=status.HTTP_400_BAD_REQUEST)
transaction = self.get_object()
transaction.valide = valide
transaction.save()
fields = ['valide']
serializer = self.get_serializer(transaction, data=request.data, partial=True, fields=fields)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response({}, status=status.HTTP_200_OK)
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