refactor_endpoints_to_api_views #84 #85
| @@ -3,8 +3,8 @@ from rest_framework.response import Response | ||||
| from rest_framework.status import HTTP_400_BAD_REQUEST | ||||
| from rest_framework.views import APIView | ||||
|  | ||||
| from .models import Sale, SaleLine, Customer, Product, ReconciliationJar | ||||
| from .serializers import SaleSerializer, ProductSerializer, CustomerSerializer, ReconciliationJarSerializer | ||||
| from .models import Sale, SaleLine, Customer, Product, ReconciliationJar, PaymentMethods | ||||
| from .serializers import SaleSerializer, ProductSerializer, CustomerSerializer, ReconciliationJarSerializer, PaymentMethodSerializer | ||||
|  | ||||
| from decimal import Decimal | ||||
| import json | ||||
| @@ -100,3 +100,9 @@ class ReconciliateJarView(APIView): | ||||
|             purchase.reconciliation = reconciliation | ||||
|             purchase.clean() | ||||
|             purchase.save() | ||||
|  | ||||
|  | ||||
| class PaymentMethodView(APIView): | ||||
|     def get(self, request): | ||||
|         serializer = PaymentMethodSerializer(PaymentMethods.choices, many=True) | ||||
|         return Response(serializer.data) | ||||
|   | ||||
| @@ -38,3 +38,13 @@ class ReconciliationJarSerializer(serializers.ModelSerializer): | ||||
|             'cash_discrepancy', | ||||
|             'total_cash_purchases', | ||||
|         ] | ||||
|  | ||||
| class PaymentMethodSerializer(serializers.Serializer): | ||||
|     text = serializers.CharField() | ||||
|     value = serializers.CharField() | ||||
|  | ||||
|     def to_representation(self, instance): | ||||
|         return { | ||||
|             'text': instance[1], | ||||
|             'value': instance[0], | ||||
|         } | ||||
|   | ||||
| @@ -25,7 +25,7 @@ urlpatterns = [ | ||||
|          name="exportar_ventas_para_tryton"), | ||||
|     path("resumen_compra/<int:id>", views.purchase_summary, name="purchase_summary"), | ||||
|     path("resumen_compra_json/<int:id>", views.purchase_json_summary, name="purchase_json_summary"), | ||||
|     path("payment_methods/all/select_format", views.payment_methods_to_select, name="payment_methods_to_select"), | ||||
|     path("payment_methods/all/select_format", api_views.PaymentMethodView.as_view(), name="payment_methods_to_select"), | ||||
|     path('purchases/for_reconciliation', views.sales_for_reconciliation, name='sales_for_reconciliation'), | ||||
|     path('reconciliate_jar', api_views.ReconciliateJarView.as_view()), | ||||
|     path('api/', include(router.urls)), | ||||
|   | ||||
| @@ -152,14 +152,6 @@ def purchase_json_summary(request, id): | ||||
|     return JsonResponse(to_response, safe=False) | ||||
|  | ||||
|  | ||||
| def payment_methods_to_select(request): | ||||
|     methods = [ | ||||
|         {'text': choice[1], 'value': choice[0]} | ||||
|         for choice in PaymentMethods.choices | ||||
|     ] | ||||
|     return JsonResponse(methods, safe=False) | ||||
|  | ||||
|  | ||||
| def sales_for_reconciliation(request): | ||||
|     sales = Sale.objects.filter(reconciliation=None) | ||||
|     grouped_sales = {} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user