|
|
from django.db.models import Q
|
|
|
from drf_yasg import openapi
|
|
|
from drf_yasg.utils import swagger_auto_schema
|
|
|
from rest_framework import viewsets
|
|
|
from rest_framework.decorators import action
|
|
|
|
|
|
from ERP_5.utils.base_views import MultipleDestroyMixin, MultipleAuditMixin
|
|
|
from ERP_5.utils.paginations import GlobalPagination
|
|
|
from sale_info.models import SaleModel
|
|
|
from sale_info.serializer.sale_serializer import SaleSerializer
|
|
|
|
|
|
|
|
|
class SalesView(viewsets.ModelViewSet, MultipleDestroyMixin, MultipleAuditMixin):
|
|
|
"""
|
|
|
create:
|
|
|
销售单--新增,注意:其中images_list="1,2,3,4";里面是附件的ID
|
|
|
|
|
|
销售单新增, status: 201(成功), return: 新增销售单信息
|
|
|
|
|
|
destroy:
|
|
|
销售单--删除
|
|
|
|
|
|
销售单删除, status: 204(成功), return: None
|
|
|
|
|
|
multiple_delete:
|
|
|
销售单--批量删除,必传参数:ids=[1,2,3,4...]
|
|
|
|
|
|
销售单批量删除, status: 204(成功), return: None
|
|
|
|
|
|
update:
|
|
|
销售单--修改,注意:其中images_list="1,2,3,4";里面是附件的ID
|
|
|
|
|
|
销售单修改, status: 200(成功), return: 修改后的销售单信息
|
|
|
|
|
|
partial_update:
|
|
|
销售单--局部修改,可以传参任意属性的值,服务器会修改指定的属性值
|
|
|
|
|
|
销售单局部修改, status: 200(成功), return: 修改后的销售单信息
|
|
|
|
|
|
list:
|
|
|
销售单--该接口可以弃用
|
|
|
|
|
|
销售单列表信息, status: 200(成功), return: 销售单信息列表
|
|
|
|
|
|
retrieve:
|
|
|
查询某一个销售单
|
|
|
|
|
|
查询指定ID的销售单, status: 200(成功), return: 用户销售单
|
|
|
"""
|
|
|
|
|
|
queryset = SaleModel.objects.all()
|
|
|
serializer_class = SaleSerializer
|
|
|
pagination_class = GlobalPagination
|
|
|
|
|
|
def get_queryset(self):
|
|
|
if self.action == 'find': # 过滤查询
|
|
|
# 获取请求参数(在json中):
|
|
|
number_code = self.request.data.get('number_code', None)
|
|
|
keyword = self.request.data.get('keyword', None)
|
|
|
start_date = self.request.data.get('start_date', None)
|
|
|
end_date = self.request.data.get('end_date', None)
|
|
|
customer = self.request.data.get('customer', 0)
|
|
|
operator_user = self.request.data.get('operator_user', 0)
|
|
|
status = self.request.data.get('status', None)
|
|
|
query = Q()
|
|
|
if keyword:
|
|
|
child_query = Q()
|
|
|
child_query.add(Q(item_list__name__contains=keyword), 'OR')
|
|
|
child_query.add(Q(item_list__specification=keyword), 'OR')
|
|
|
query.add(child_query, 'AND')
|
|
|
if start_date:
|
|
|
query.add(Q(invoices_date__gt=start_date), 'AND')
|
|
|
if end_date:
|
|
|
query.add(Q(invoices_date__lt=end_date), 'AND')
|
|
|
|
|
|
if customer:
|
|
|
query.add(Q(customer__id=customer), 'AND')
|
|
|
if number_code:
|
|
|
query.add(Q(number_code__contains=number_code), 'AND')
|
|
|
if operator_user:
|
|
|
query.add(Q(operator_user__id=operator_user), 'AND')
|
|
|
if status:
|
|
|
query.add(Q(status=status), 'AND')
|
|
|
|
|
|
return SaleModel.objects.filter(query).distinct().all()
|
|
|
else:
|
|
|
return SaleModel.objects.all()
|
|
|
|
|
|
|
|
|
params = openapi.Schema(type=openapi.TYPE_OBJECT, properties={
|
|
|
'keyword': openapi.Schema(type=openapi.TYPE_STRING, description="名称的关键字或者型号"),
|
|
|
'start_date': openapi.Schema(type=openapi.TYPE_STRING, description="起始日期2020-10-01"),
|
|
|
'number_code': openapi.Schema(type=openapi.TYPE_STRING, description="编号(序列号)"),
|
|
|
'end_date': openapi.Schema(type=openapi.TYPE_STRING, description="结束日期2020-10-01"),
|
|
|
'status': openapi.Schema(type=openapi.TYPE_STRING, description="状态0或者1,2,3.."),
|
|
|
'customer': openapi.Schema(type=openapi.TYPE_INTEGER, description="客户商的ID"),
|
|
|
'operator_user': openapi.Schema(type=openapi.TYPE_INTEGER, description="操作用户的ID"),
|
|
|
})
|
|
|
|
|
|
# 分页参数必须是query_param(看源码)
|
|
|
page_param = openapi.Parameter(name='page', in_=openapi.IN_QUERY, description="页号", type=openapi.TYPE_INTEGER)
|
|
|
size_param = openapi.Parameter(name='size', in_=openapi.IN_QUERY, description="每页显示数量", type=openapi.TYPE_INTEGER)
|
|
|
|
|
|
@swagger_auto_schema(method='POST', request_body=params, manual_parameters=[page_param, size_param],
|
|
|
operation_description="销售订单的搜索过滤")
|
|
|
@action(methods=['POST'], detail=False)
|
|
|
def find(self, request, *args, **kwargs):
|
|
|
return super(SalesView, self).list(request=request, *args, **kwargs)
|