small changes
This commit is contained in:
1 parent
e983e0cc43
commit
f7dbd02a6c
36 files changed
+704
-16
No files matched your search
@@ -8,9 +8,12 @@ from .product import (
|
||||
)
|
||||
|
||||
from .order import (
|
||||
OrderListOperatorApi, OrderRetrieveOperatorApi, OrderRetrieveOperatorExcelApi,
|
||||
OrderCreateApi, OrderUpdateApi, OrderDeleteApi, OrderRetrieveApi, OrderListApi, OrderAndItemCreateApi
|
||||
)
|
||||
|
||||
from .cart import (CartListApi, CartCreateApi, CartDeleteApi)
|
||||
|
||||
from .order_item import (OrderItemsListApi, )
|
||||
|
||||
from .excel_import import ImportExcelView
|
||||
@@ -0,0 +1,39 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
import pandas as pd
|
||||
from apps.shop.models import Product as ProductModel, ProductCategory as ProductCategoryModel
|
||||
from apps.workspace.models import Workspace as WorkspaceModel
|
||||
import os
|
||||
|
||||
|
||||
class ImportExcelView(APIView):
|
||||
|
||||
def get(self, request):
|
||||
|
||||
df = pd.read_excel('pe.xlsx')
|
||||
for index, row in df.iterrows():
|
||||
cate_name = row['cate_name']
|
||||
order_cat = row['order_cat']
|
||||
acc_code = row['acc_code']
|
||||
prd_name = row['prd_name']
|
||||
order_prd = row['order_prd']
|
||||
vahed = row['vahed']
|
||||
|
||||
workspace = WorkspaceModel.objects.get(id=2)
|
||||
try:
|
||||
prd_ct = ProductCategoryModel.objects.get(name=cate_name, sys_ws=workspace, order_cat=order_cat)
|
||||
except ProductCategoryModel.DoesNotExist as exp:
|
||||
prd_ct = ProductCategoryModel.objects.create(name=cate_name, sys_ws=workspace, order_cat=order_cat)
|
||||
|
||||
new_product = ProductModel()
|
||||
new_product.name = prd_name
|
||||
new_product.price = 0
|
||||
new_product.category = ProductCategoryModel.objects.get(id=prd_ct.id)
|
||||
new_product.acc_code = acc_code
|
||||
new_product.order_prd = order_prd
|
||||
new_product.attr = {"acc_vahed": vahed}
|
||||
new_product.sys_ws = workspace
|
||||
new_product.save()
|
||||
|
||||
return Response(data={"result": 'ok'})
|
||||
|
||||
@@ -11,6 +11,9 @@ from rest_framework import generics
|
||||
from apps.customer.models import Customer as CustomerModel
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from utils import custom_permissions
|
||||
from utils.tools import inline_serializer
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
|
||||
class OrderCreateApi(APIView):
|
||||
@@ -150,3 +153,74 @@ class OrderListApi(generics.ListAPIView):
|
||||
|
||||
return list_order(cuser_role_uuid=cuser_role_uuid, workspace_uuid=user_workspace_uuid)
|
||||
|
||||
|
||||
class OrderListOperatorApi(generics.ListAPIView):
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
customer = inline_serializer(fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name_family': serializers.CharField(),
|
||||
})
|
||||
class Meta:
|
||||
model = OrderModel
|
||||
exclude = ('sys_ws', )
|
||||
|
||||
serializer_class = OutputSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
return list_order_operators(self.request)
|
||||
|
||||
|
||||
class OrderRetrieveOperatorApi(APIView):
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
|
||||
customer = inline_serializer(fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name_family': serializers.CharField(),
|
||||
})
|
||||
|
||||
order_item = inline_serializer(many=True, fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'product': inline_serializer(fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField(),
|
||||
'category': inline_serializer(fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField(),
|
||||
})
|
||||
}),
|
||||
'product_name': serializers.CharField(),
|
||||
'price': serializers.IntegerField(),
|
||||
'amount': serializers.IntegerField(),
|
||||
})
|
||||
|
||||
class Meta:
|
||||
model = OrderModel
|
||||
exclude = ('sys_ws', )
|
||||
|
||||
serializer_class = OutputSerializer
|
||||
|
||||
def get(self, request, order_id):
|
||||
|
||||
order = retrieve_order_operators(request, order_id=order_id)
|
||||
|
||||
output = self.OutputSerializer(order)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class OrderRetrieveOperatorExcelApi(APIView):
|
||||
def get(self, request, order_id):
|
||||
|
||||
order_df = retrieve_order_item_excel(request=request, order_id=order_id)
|
||||
|
||||
excel_file = BytesIO()
|
||||
order_df.to_excel(excel_file, engine='xlsxwriter', index=False)
|
||||
excel_file.seek(0)
|
||||
|
||||
response = HttpResponse(excel_file.read(), content_type='application/ms-excel')
|
||||
response['Content-Disposition'] = 'attachment; filename="output.xlsx"'
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ class ProductListCategoryApi(generics.ListAPIView):
|
||||
)
|
||||
data = {
|
||||
"category_name": category.name,
|
||||
"category_img": category.image.url,
|
||||
"products": serializer.data
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ class ProductsCategoryApi(APIView):
|
||||
|
||||
def get(self, request):
|
||||
|
||||
p_cate = ProductCategoryModel.objects.annotate(product_count=Count('product')).filter(product_count__gte=1)
|
||||
p_cate = ProductCategoryModel.objects.annotate(product_count=Count('product')).filter(product_count__gte=1).order_by('order_cat')
|
||||
output = self.OutputSerializer(p_cate, many=True)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
Reference in new issue
Block a user