Creada vista para listar los cuadres de tarro #90 #91
| @@ -2,6 +2,7 @@ from rest_framework import viewsets | |||||||
| from rest_framework.response import Response | from rest_framework.response import Response | ||||||
| from rest_framework.status import HTTP_400_BAD_REQUEST | from rest_framework.status import HTTP_400_BAD_REQUEST | ||||||
| from rest_framework.views import APIView | from rest_framework.views import APIView | ||||||
|  | from rest_framework.pagination import PageNumberPagination | ||||||
|  |  | ||||||
| from .models import Sale, SaleLine, Customer, Product, ReconciliationJar, PaymentMethods, AdminCode | from .models import Sale, SaleLine, Customer, Product, ReconciliationJar, PaymentMethods, AdminCode | ||||||
| from .serializers import SaleSerializer, ProductSerializer, CustomerSerializer, ReconciliationJarSerializer, PaymentMethodSerializer, SaleForRenconciliationSerializer, SaleSummarySerializer | from .serializers import SaleSerializer, ProductSerializer, CustomerSerializer, ReconciliationJarSerializer, PaymentMethodSerializer, SaleForRenconciliationSerializer, SaleSummarySerializer | ||||||
| @@ -9,6 +10,12 @@ from .serializers import SaleSerializer, ProductSerializer, CustomerSerializer, | |||||||
| from decimal import Decimal | from decimal import Decimal | ||||||
| import json | import json | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Pagination(PageNumberPagination): | ||||||
|  |     page_size = 10 | ||||||
|  |     page_size_query_param = 'page_size' | ||||||
|  |  | ||||||
|  |  | ||||||
| class SaleView(viewsets.ModelViewSet): | class SaleView(viewsets.ModelViewSet): | ||||||
|     queryset = Sale.objects.all() |     queryset = Sale.objects.all() | ||||||
|     serializer_class = SaleSerializer |     serializer_class = SaleSerializer | ||||||
| @@ -131,3 +138,9 @@ class AdminCodeValidateView(APIView): | |||||||
|     def get(self, request, code): |     def get(self, request, code): | ||||||
|         codes = AdminCode.objects.filter(value=code) |         codes = AdminCode.objects.filter(value=code) | ||||||
|         return Response({'validCode': bool(codes)}) |         return Response({'validCode': bool(codes)}) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class ReconciliateJarModelView(viewsets.ModelViewSet): | ||||||
|  |     queryset = ReconciliationJar.objects.all().order_by('-date_time') | ||||||
|  |     pagination_class = Pagination | ||||||
|  |     serializer_class = ReconciliationJarSerializer | ||||||
|   | |||||||
| @@ -197,6 +197,34 @@ class TestJarReconcliation(TestCase): | |||||||
|         purchases = Sale.objects.filter(reconciliation_id=content['id']) |         purchases = Sale.objects.filter(reconciliation_id=content['id']) | ||||||
|         self.assertEqual(len(purchases), 3) |         self.assertEqual(len(purchases), 3) | ||||||
|  |  | ||||||
|  |     def test_list_reconciliations(self): | ||||||
|  |         self._create_simple_reconciliation() | ||||||
|  |         self._create_simple_reconciliation() | ||||||
|  |  | ||||||
|  |         url = '/don_confiao/api/reconciliate_jar/' | ||||||
|  |  | ||||||
|  |         response = self.client.get(url) | ||||||
|  |         self.assertEqual(response.status_code, 200) | ||||||
|  |  | ||||||
|  |         content = json.loads(response.content.decode('utf-8')) | ||||||
|  |         self.assertEqual(2, len(content['results'])) | ||||||
|  |         self.assertEqual('2024-07-30T00:00:00Z', | ||||||
|  |                          content['results'][0]['date_time']) | ||||||
|  |  | ||||||
|  |     def test_list_reconciliations_pagination(self): | ||||||
|  |         self._create_simple_reconciliation() | ||||||
|  |         self._create_simple_reconciliation() | ||||||
|  |  | ||||||
|  |         url = '/don_confiao/api/reconciliate_jar/?page=2&page_size=1' | ||||||
|  |  | ||||||
|  |         response = self.client.get(url) | ||||||
|  |         self.assertEqual(response.status_code, 200) | ||||||
|  |  | ||||||
|  |         content = json.loads(response.content.decode('utf-8')) | ||||||
|  |         self.assertEqual(1, len(content['results'])) | ||||||
|  |         self.assertEqual('2024-07-30T00:00:00Z', | ||||||
|  |                          content['results'][0]['date_time']) | ||||||
|  |  | ||||||
|     def _create_simple_reconciliation(self): |     def _create_simple_reconciliation(self): | ||||||
|         reconciliation = ReconciliationJar() |         reconciliation = ReconciliationJar() | ||||||
|         reconciliation.date_time = "2024-07-30" |         reconciliation.date_time = "2024-07-30" | ||||||
|   | |||||||
| @@ -10,7 +10,8 @@ router = DefaultRouter() | |||||||
| router.register(r'sales', api_views.SaleView, basename='sale') | router.register(r'sales', api_views.SaleView, basename='sale') | ||||||
| router.register(r'customers', api_views.CustomerView, basename='customer') | router.register(r'customers', api_views.CustomerView, basename='customer') | ||||||
| router.register(r'products', api_views.ProductView, basename='product') | router.register(r'products', api_views.ProductView, basename='product') | ||||||
|  | router.register(r'reconciliate_jar', api_views.ReconciliateJarModelView, | ||||||
|  |                 basename='reconciliate_jar') | ||||||
|  |  | ||||||
| urlpatterns = [ | urlpatterns = [ | ||||||
|     path("", views.index, name="wellcome"), |     path("", views.index, name="wellcome"), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user