Browse Source

客户报备

hujingpei 4 years ago
parent
commit
83635dc83e
3 changed files with 57 additions and 40 deletions
  1. 26 17
      apps/customer/models.py
  2. 1 1
      apps/customer/serializers.py
  3. 30 22
      apps/customer/views.py

+ 26 - 17
apps/customer/models.py

@@ -24,7 +24,8 @@ class ReportCustomer(models.Model):
     village = models.CharField(max_length=100, verbose_name=u'小区')
     village = models.CharField(max_length=100, verbose_name=u'小区')
     address = models.CharField(max_length=100, verbose_name=u'地址')
     address = models.CharField(max_length=100, verbose_name=u'地址')
     source = models.ForeignKey(Option, verbose_name=u'来源', related_name='customer_source', on_delete=models.PROTECT)
     source = models.ForeignKey(Option, verbose_name=u'来源', related_name='customer_source', on_delete=models.PROTECT)
-    project = models.ManyToManyField(Option, verbose_name=u'项目', related_name='customer_category', editable=False, null=True,blank=True)
+    project = models.ManyToManyField(Option, verbose_name=u'项目', related_name='customer_category', editable=False,
+                                     null=True,blank=True)
     notes = models.CharField(max_length=500, verbose_name=u"备注", null=True)
     notes = models.CharField(max_length=500, verbose_name=u"备注", null=True)
     report_status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'报备状态', default=NOT_CHECKED)
     report_status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'报备状态', default=NOT_CHECKED)
     check_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'审核人', related_name='customer_check_user',
     check_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'审核人', related_name='customer_check_user',
@@ -41,22 +42,30 @@ class ReportCustomer(models.Model):
         ordering = ['-id']
         ordering = ['-id']
         default_permissions = ()
         default_permissions = ()
         permissions = [
         permissions = [
-            ('view_customer', u'查看'),
-            ('add_customer', u'添加'),
-            ('update_customer', u'更新'),
-            ('delete_customer', u'删除'),
-            ('check_customer', u'审核'),
+            ('view_report_customer', u'查看'),
+            ('add_report_customer', u'添加'),
+            ('update_report_customer', u'更新'),
+            ('delete_report_customer', u'删除'),
+            ('check_report_customer', u'审核'),
         ]
         ]
 
 
-    def check_customer(self, user):
+    # def check_customer(self, user):
+    #     # 审核
+    #     if self.report_status == ReportCustomer.REPEAT_REPORT:
+    #
+    #
+    #     if self.report_status == ReportCustomer.NOT_CHECKED:
+    #         self.check_user = user
+    #         self.report_status = ReportCustomer.CHECKED
+    #         self.check_time = timezone.now()
+    #         self.save()
+    #     # if self.report_status == Customer.CHECKED:
+    #     #     # 撞单
+
+
+    def check_order(self, user):
         # 审核
         # 审核
-        if self.report_status == ReportCustomer.REPEAT_REPORT:
-            raise CustomError('当前客户报备状态为重复报备!')
-
-        if self.report_status == ReportCustomer.NOT_CHECKED:
-            self.check_user = user
-            self.report_status = ReportCustomer.CHECKED
-            self.check_time = timezone.now()
-            self.save()
-        # if self.report_status == Customer.CHECKED:
-        #     # 撞单
+        self.check_user = user
+        self.check_time = timezone.now()
+        self.check_status = self.PASS
+        self.save()

+ 1 - 1
apps/customer/serializers.py

@@ -45,5 +45,5 @@ class ReportCustomerSerializer(serializers.ModelSerializer):
 
 
         for project in projects:
         for project in projects:
             instance.project.add(project)
             instance.project.add(project)
+        instance = super(ReportCustomerSerializer, self).update(instance, validated_data)
         return instance
         return instance
-

+ 30 - 22
apps/customer/views.py

@@ -1,14 +1,17 @@
 # coding=utf-8
 # coding=utf-8
 from rest_framework.views import APIView
 from rest_framework.views import APIView
 from django.db.models import Q
 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.custom_modelviewset import CustomModelViewSet
 from utils import response_ok, response_error
 from utils import response_ok, response_error
+from utils.exceptions import CustomError
 from apps.option.models import Option
 from apps.option.models import Option
 from apps.option.serializers import OptionComboboxSerializer
 from apps.option.serializers import OptionComboboxSerializer
 from .models import ReportCustomer
 from .models import ReportCustomer
 from .serializers import ReportCustomerSerializer
 from .serializers import ReportCustomerSerializer
-from .filters import ReportCustomerFilter,ReportCheckFilter
+from .filters import ReportCustomerFilter
 
 
 
 
 class ReportCustomerViewSet(CustomModelViewSet):
 class ReportCustomerViewSet(CustomModelViewSet):
@@ -35,25 +38,32 @@ class ReportCustomerViewSet(CustomModelViewSet):
         super(ReportCustomerViewSet, self).perform_destroy(instance)
         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):
 class ReportCustomerDictView(APIView):
     permission_classes = []
     permission_classes = []
@@ -67,5 +77,3 @@ class ReportCustomerDictView(APIView):
             'source': serializer_scouce.data,
             'source': serializer_scouce.data,
             'project': serializer_project.data,
             'project': serializer_project.data,
         })
         })
-
-