Browse Source

Merge branch 'master' of http://git.zzliaoyuan.com:4000/wushaodong/ly_baoxiu_admin

lijiangwei 4 years ago
parent
commit
2ba6e440b3
1 changed files with 13 additions and 12 deletions
  1. 13 12
      apps/tenant/employee/serializers.py

+ 13 - 12
apps/tenant/employee/serializers.py

@@ -24,9 +24,14 @@ class EmployeeSerializer(serializers.ModelSerializer):
     def create(self, validated_data):
         if int(self.initial_data['type']) == Employee.SUPER and Employee.checkSuper(self.context['request'].user.employee.tenant):
             raise CustomError(u'已存在一个平台管理员,禁止操作!')
-        username = self.initial_data['tel']
+        #标准版 限制检修人人数为2
+        tenant = self.context['request'].user.employee.tenant
+        employees = Employee.objects.filter(tenant=tenant, status=Employee.ENABLE,type=Employee.EMPLOYEE).count()
+        if int(self.initial_data['type']) == Employee.EMPLOYEE and employees >= 2 and tenant.edition == Tenant.EDITION_1:
+            raise CustomError(u'当前版本,仅能添加2个检修人。如有需要,请升级到更高版本!')
         # 判断用户是否已经注册登陆过
         password = None
+        username = self.initial_data['tel']
         if self.initial_data['password']:
             password = self.initial_data['password']
         user = User.objects.filter(username=username).first()
@@ -34,12 +39,6 @@ class EmployeeSerializer(serializers.ModelSerializer):
             # 创建user实例
             user = User.objects.create_tenant_user(validated_data['type'], username, password)
 
-        #标准版 限制检修人人数为2
-        tenant = self.context['request'].user.employee.tenant
-        employees = Employee.objects.filter(tenant=tenant, type=Employee.EMPLOYEE).count()
-        if employees >= 2 and tenant.edition == Tenant.EDITION_1:
-            raise CustomError(u'只能添加2个检修人!')
-
         validated_data['user'] = user
         validated_data['tenant'] = self.context['request'].user.employee.tenant
 
@@ -50,11 +49,17 @@ class EmployeeSerializer(serializers.ModelSerializer):
             if e.args[0] == 1062:
                 raise CustomError(u'该手机号已被游客或者其他员工使用,请检查!')
 
+
     def update(self, instance, validated_data):
         if instance.tenant != self.context['request'].user.employee.tenant:
             raise CustomError(u'禁止跨企业操作!')
         if int(self.initial_data['type']) == Employee.SUPER and Employee.checkSuper(instance.tenant, instance.id):
             raise CustomError(u'已存在一个平台管理员,禁止操作!')
+        # 标准版 限制检修人人数为2
+        employees = Employee.objects.filter(tenant=instance.tenant, status=Employee.ENABLE,type=Employee.EMPLOYEE).count()
+        if int(self.initial_data['type']) == Employee.EMPLOYEE and employees >= 2 and instance.tenant.edition == Tenant.EDITION_1:
+            raise CustomError(u'当前版本,仅能添加2个检修人。如有需要,请升级到更高版本!')
+
         username = self.initial_data['tel']
         if username and self.initial_data['password'].strip() != '':
             if instance.user:
@@ -73,10 +78,6 @@ class EmployeeSerializer(serializers.ModelSerializer):
                                                        is_active=is_active)
                 validated_data['user'] = user
 
-        # 标准版 限制检修人人数为2
-        employees = Employee.objects.filter(tenant=instance.tenant,type=Employee.EMPLOYEE).count()
-        if employees >= 2 and instance.tenant.edition == Tenant.EDITION_1:
-            raise CustomError(u'只能添加2个检修人!')
-
         instance = super(EmployeeSerializer, self).update(instance, validated_data)
+
         return instance