Showing
3 changed files
with
11 additions
and
20 deletions
@@ -12,12 +12,9 @@ class PrecioAdmin(admin.ModelAdmin): | @@ -12,12 +12,9 @@ class PrecioAdmin(admin.ModelAdmin): | ||
12 | precios_activos = Precio.objects.filter(vigencia_hasta__gte=timezone.now().date()) | 12 | precios_activos = Precio.objects.filter(vigencia_hasta__gte=timezone.now().date()) |
13 | if not change: | 13 | if not change: |
14 | today = timezone.now().date() | 14 | today = timezone.now().date() |
15 | - if obj.vigencia_desde <= today: | ||
16 | - if not precios_activos.exists(): | 15 | + if obj.vigencia_desde <= today and not precios_activos.exists(): |
17 | obj.save() | 16 | obj.save() |
18 | else: | 17 | else: |
19 | - raise ValidationError("Ya existe un precio activo.") | ||
20 | - else: | ||
21 | raise ValidationError("La fecha de inicio no es válida.") | 18 | raise ValidationError("La fecha de inicio no es válida.") |
22 | else: | 19 | else: |
23 | obj.save() | 20 | obj.save() |
@@ -57,12 +57,7 @@ class PrecioViewSet(viewsets.ReadOnlyModelViewSet): | @@ -57,12 +57,7 @@ class PrecioViewSet(viewsets.ReadOnlyModelViewSet): | ||
57 | queryset = Precio.objects.all() | 57 | queryset = Precio.objects.all() |
58 | 58 | ||
59 | 59 | ||
60 | -class PagoViewSets(mixins.CreateModelMixin, | ||
61 | - mixins.RetrieveModelMixin, | ||
62 | - mixins.UpdateModelMixin, | ||
63 | - mixins.DestroyModelMixin, | ||
64 | - mixins.ListModelMixin, | ||
65 | - viewsets.GenericViewSet): | 60 | +class PagoViewSets(viewsets.ModelViewSet): |
66 | serializer_class = PagoSerializer | 61 | serializer_class = PagoSerializer |
67 | permission_classes = [IsAuthenticated, IsAdminOrAuthorized] | 62 | permission_classes = [IsAuthenticated, IsAdminOrAuthorized] |
68 | queryset = ComprobantePago.objects.all() | 63 | queryset = ComprobantePago.objects.all() |
@@ -70,17 +65,16 @@ class PagoViewSets(mixins.CreateModelMixin, | @@ -70,17 +65,16 @@ class PagoViewSets(mixins.CreateModelMixin, | ||
70 | def perform_create(self, serializer): | 65 | def perform_create(self, serializer): |
71 | try: | 66 | try: |
72 | edicto = Edicto.objects.get(estado='pendiente_de_pago') | 67 | edicto = Edicto.objects.get(estado='pendiente_de_pago') |
73 | - precio = Precio.objects.latest('id') | ||
74 | - monto = calculadora(edicto, precio) | ||
75 | if edicto.usuario != self.request.user: | 68 | if edicto.usuario != self.request.user: |
76 | raise UsuarioNoAutorizado | 69 | raise UsuarioNoAutorizado |
77 | - serializer.validated_data['monto'] = monto | ||
78 | - serializer.validated_data['edicto'] = edicto | 70 | + |
71 | + precio = Precio.objects.latest('id') | ||
72 | + monto = calculadora(edicto, precio) | ||
73 | + | ||
74 | + serializer.validated_data.update({'monto': monto, 'edicto': edicto}) | ||
79 | serializer.save() | 75 | serializer.save() |
80 | - except Edicto.DoesNotExist: | ||
81 | - raise EdictoNoEncontrado | ||
82 | - except Precio.DoesNotExist: | ||
83 | - raise PrecioNoEncontrado | 76 | + except (Edicto.DoesNotExist, Precio.DoesNotExist): |
77 | + raise EdictoOPrecioNoEncontrado | ||
84 | 78 | ||
85 | 79 | ||
86 | class ComprobanteViewSets(mixins.CreateModelMixin, | 80 | class ComprobanteViewSets(mixins.CreateModelMixin, |
@@ -42,7 +42,7 @@ class Edicto(models.Model): | @@ -42,7 +42,7 @@ class Edicto(models.Model): | ||
42 | verbose_name_plural = 'Edictos' | 42 | verbose_name_plural = 'Edictos' |
43 | 43 | ||
44 | def __str__(self): | 44 | def __str__(self): |
45 | - return f"{self.cuerpo_edicto} Edicto" | 45 | + return f"{self.usuario} - Edicto" |
46 | 46 | ||
47 | 47 | ||
48 | class ComprobantePago(models.Model): | 48 | class ComprobantePago(models.Model): |
@@ -57,4 +57,4 @@ class ComprobantePago(models.Model): | @@ -57,4 +57,4 @@ class ComprobantePago(models.Model): | ||
57 | verbose_name_plural = 'ComprobantesPagos' | 57 | verbose_name_plural = 'ComprobantesPagos' |
58 | 58 | ||
59 | def __str__(self): | 59 | def __str__(self): |
60 | - return f"{self.numero_comprobante} comprobante pago de {self.edicto.cuerpo_edicto}" | 60 | + return f"{self.numero_comprobante} comprobante pago de {self.edicto.usuario}" |
-
Please register or login to post a comment