Martín Miranda

Merge branch 'feature/#80_crear_endpoint_para_precios_que_permita_abm' into 'develop'

modificaciones en endpoint en el serializer de precio



See merge request !74
@@ -44,12 +44,17 @@ class EdictoViewSet(AuditoriaMixin, mixins.CreateModelMixin, @@ -44,12 +44,17 @@ class EdictoViewSet(AuditoriaMixin, mixins.CreateModelMixin,
44 return Response(serializer.data) 44 return Response(serializer.data)
45 45
46 46
47 -class PrecioViewSet(AuditoriaMixin, viewsets.ReadOnlyModelViewSet): 47 +class PrecioViewSet(mixins.CreateModelMixin,
  48 + mixins.RetrieveModelMixin,
  49 + mixins.UpdateModelMixin,
  50 + mixins.ListModelMixin,
  51 + viewsets.GenericViewSet,
  52 + ):
48 serializer_class = PrecioSerializer 53 serializer_class = PrecioSerializer
49 permission_classes = [IsAuthenticated, IsAdminOrAuthorized] 54 permission_classes = [IsAuthenticated, IsAdminOrAuthorized]
50 filter_backends = (DjangoFilterBackend, filters.OrderingFilter) 55 filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
51 filterset_class = PrecioFilter 56 filterset_class = PrecioFilter
52 - ordering_fields = ('usuario',) 57 + ordering_fields = ('usuario', 'id',)
53 ordering = 'usuario' 58 ordering = 'usuario'
54 queryset = Precio.objects.all() 59 queryset = Precio.objects.all()
55 60
@@ -65,7 +70,7 @@ class ComprobanteViewSet(mixins.UpdateModelMixin, @@ -65,7 +70,7 @@ class ComprobanteViewSet(mixins.UpdateModelMixin,
65 queryset = ComprobantePago.objects.all() 70 queryset = ComprobantePago.objects.all()
66 filter_backends = (DjangoFilterBackend, filters.OrderingFilter) 71 filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
67 filter_class = ComprobanteFilter 72 filter_class = ComprobanteFilter
68 - ordering_fields = ('id','monto_descuento', 'monto_total', 'fecha_pago') 73 + ordering_fields = ('id', 'monto_descuento', 'monto_total', 'fecha_pago')
69 ordering = 'id' 74 ordering = 'id'
70 75
71 76
@@ -84,6 +84,20 @@ class PrecioSerializer(serializers.ModelSerializer): @@ -84,6 +84,20 @@ class PrecioSerializer(serializers.ModelSerializer):
84 included_serializers = {'usuario': UsuarioListaSerializer 84 included_serializers = {'usuario': UsuarioListaSerializer
85 } 85 }
86 86
  87 + def validate(self, data):
  88 + data['usuario'] = self.context['request'].user
  89 + vigencia_hasta = data.get('vigencia_hasta')
  90 +
  91 + if not vigencia_hasta:
  92 + precios_sin_vigencia = Precio.objects.filter(vigencia_hasta__isnull=True)
  93 + if precios_sin_vigencia.exists():
  94 + raise serializers.ValidationError(
  95 + 'Error al agregar: Ya existe un objeto Precio sin vigencia_hasta. '
  96 + 'Debe proporcionar una fecha para vigencia_hasta antes de crear un nuevo objeto Precio.'
  97 + )
  98 +
  99 + return data
  100 +
87 101
88 class ComprobanteSerializer(serializers.ModelSerializer): 102 class ComprobanteSerializer(serializers.ModelSerializer):
89 class Meta: 103 class Meta: