fix(api): remove SaleWithLinesViewSet.
This commit is contained in:
		| @@ -2,18 +2,18 @@ from rest_framework import viewsets | ||||
| from rest_framework.response import Response | ||||
|  | ||||
| from .models import Sale, SaleLine, Customer, Product | ||||
| from .serializers import SaleSerializer, SaleWithLinesSerializer, ProductSerializer, CustomerSerializer | ||||
| from .serializers import SaleSerializer, ProductSerializer, CustomerSerializer | ||||
|  | ||||
|  | ||||
| class SaleWithLinesViewSet(viewsets.ModelViewSet): | ||||
| class SaleView(viewsets.ModelViewSet): | ||||
|     queryset = Sale.objects.all() | ||||
|     serializer_class = SaleWithLinesSerializer | ||||
|     serializer_class = SaleSerializer | ||||
|  | ||||
|     def create(self, request): | ||||
|         data = request.data | ||||
|         customer = Customer.objects.get(pk=data['customer']) | ||||
|         date = data['date'] | ||||
|         lines = data['lines'] | ||||
|         lines = data['saleline_set'] | ||||
|         sale = Sale.objects.create(customer=customer, date=date) | ||||
|  | ||||
|         for line in lines: | ||||
| @@ -30,11 +30,6 @@ class SaleWithLinesViewSet(viewsets.ModelViewSet): | ||||
|         return Response({'message': 'Venta creada con exito'}, status=201) | ||||
|  | ||||
|  | ||||
| class SaleView(viewsets.ModelViewSet): | ||||
|     queryset = Sale.objects.all() | ||||
|     serializer_class = SaleSerializer | ||||
|  | ||||
|  | ||||
| class ProductView(viewsets.ModelViewSet): | ||||
|     queryset = Product.objects.all() | ||||
|     serializer_class = ProductSerializer | ||||
|   | ||||
| @@ -9,23 +9,10 @@ class SaleLineSerializer(serializers.ModelSerializer): | ||||
|         fields = ['id', 'sale', 'product', 'unit_price', 'quantity'] | ||||
|  | ||||
|  | ||||
| class SaleWithLinesSerializer(serializers.ModelSerializer): | ||||
|     lines = SaleLineSerializer(many=True) | ||||
|  | ||||
|     class Meta: | ||||
|         model = Sale | ||||
|         fields = ['id', 'customer', 'date', 'lines'] | ||||
|  | ||||
|  | ||||
| class SaleSerializer(serializers.ModelSerializer): | ||||
|     class Meta: | ||||
|         model = Sale | ||||
|         fields = ['id', 'customer', 'date'] | ||||
|  | ||||
|     def to_representation(self, instance): | ||||
|         representation = super().to_representation(instance) | ||||
|         representation['lines'] = [line for line in instance.saleline_set.all().values()] | ||||
|         return representation | ||||
|         fields = ['id', 'customer', 'date', 'saleline_set'] | ||||
|  | ||||
|  | ||||
| class ProductSerializer(serializers.ModelSerializer): | ||||
|   | ||||
| @@ -21,7 +21,7 @@ class TestAPI(APITestCase): | ||||
|         data = { | ||||
|             'customer': self.customer.id, | ||||
|             'date': '2024-09-02', | ||||
|             'lines': [ | ||||
|             'saleline_set': [ | ||||
|                 {'product': self.product.id, 'quantity': 2, 'unit_price': 3000}, | ||||
|                 {'product': self.product.id, 'quantity': 3, 'unit_price': 5000} | ||||
|             ], | ||||
|   | ||||
| @@ -22,6 +22,5 @@ urlpatterns = [ | ||||
|     path("cuadrar_tarro", views.reconciliate_jar, name="reconciliate_jar"), | ||||
|     path("cuadres", views.reconciliate_jar, name="reconciliations"), | ||||
|     path("resumen_compra/<int:id>", views.purchase_summary, name="purchase_summary"), | ||||
|     path('api/sales_with_lines/', api_views.SaleWithLinesViewSet.as_view({'post': 'create'}), name='sale-create'), | ||||
|     path('api/', include(router.urls)), | ||||
| ] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user