|
@@ -1,14 +1,17 @@
|
|
|
# coding=utf-8
|
|
|
from rest_framework.views import APIView
|
|
|
from django.db.models import Q
|
|
|
+from django.utils import timezone
|
|
|
+from rest_framework.decorators import action
|
|
|
|
|
|
from utils.custom_modelviewset import CustomModelViewSet
|
|
|
from utils import response_ok, response_error
|
|
|
+from utils.exceptions import CustomError
|
|
|
from apps.option.models import Option
|
|
|
from apps.option.serializers import OptionComboboxSerializer
|
|
|
from .models import ReportCustomer
|
|
|
from .serializers import ReportCustomerSerializer
|
|
|
-from .filters import ReportCustomerFilter,ReportCheckFilter
|
|
|
+from .filters import ReportCustomerFilter
|
|
|
|
|
|
|
|
|
class ReportCustomerViewSet(CustomModelViewSet):
|
|
@@ -35,25 +38,32 @@ class ReportCustomerViewSet(CustomModelViewSet):
|
|
|
super(ReportCustomerViewSet, self).perform_destroy(instance)
|
|
|
|
|
|
|
|
|
- # @action(methods=['post'], detail=False)
|
|
|
- # def check(self, request, pk):
|
|
|
- # # 审核
|
|
|
- # report_status = request.POST.get('report_status')
|
|
|
- # try:
|
|
|
- # instance = Customer.objects.filter(id=pk).first()
|
|
|
- # if not instance:
|
|
|
- # raise CustomError('当前客户报备信息有误!')
|
|
|
- #
|
|
|
- # instance.check_user = self.request.user
|
|
|
- # instance.report_status = report_status
|
|
|
- # instance.check_time = timezone.now()
|
|
|
- # instance.save()
|
|
|
- #
|
|
|
- # except CustomError as e:
|
|
|
- # return response_error(e.get_error_msg())
|
|
|
- # except Exception as e:
|
|
|
- # return response_error(str(e))
|
|
|
- # return response_ok('审核完成!')
|
|
|
+ @action(methods=['post'], detail=False)
|
|
|
+ def check(self, request, pk):
|
|
|
+ # 审核
|
|
|
+ report_status = request.POST.get('report_status')
|
|
|
+ try:
|
|
|
+ instance = ReportCustomer.objects.filter(id=pk).first()
|
|
|
+ if not instance:
|
|
|
+ raise CustomError('当前客户报备信息有误!')
|
|
|
+ if report_status == ReportCustomer.REPEAT_REPORT:
|
|
|
+ raise CustomError('当前客户报备状态为重复报备!')
|
|
|
+ if instance.report_status == ReportCustomer.CHECKED and report_status == ReportCustomer.CHECKED:
|
|
|
+ # 撞单
|
|
|
+ instance.check_user = self.request.user
|
|
|
+ instance.report_status = ReportCustomer.REPEAT_REPORT
|
|
|
+ instance.check_time = timezone.now()
|
|
|
+ instance.save()
|
|
|
+ if instance.report_status == ReportCustomer.NOT_CHECKED and report_status == ReportCustomer.CHECKED:
|
|
|
+ instance.check_user = self.request.user
|
|
|
+ instance.report_status = ReportCustomer.CHECKED
|
|
|
+ instance.check_time = timezone.now()
|
|
|
+ instance.save()
|
|
|
+ except CustomError as e:
|
|
|
+ return response_error(e.get_error_msg())
|
|
|
+ except Exception as e:
|
|
|
+ return response_error(str(e))
|
|
|
+ return response_ok('审核完成!')
|
|
|
|
|
|
class ReportCustomerDictView(APIView):
|
|
|
permission_classes = []
|
|
@@ -67,5 +77,3 @@ class ReportCustomerDictView(APIView):
|
|
|
'source': serializer_scouce.data,
|
|
|
'project': serializer_project.data,
|
|
|
})
|
|
|
-
|
|
|
-
|