Forráskód Böngészése

Merge remote-tracking branch 'origin/master'

lijiangwei 4 éve
szülő
commit
4d7e8da000

+ 5 - 5
apps/tenant/device/serializers.py

@@ -30,10 +30,10 @@ class DeviceSerializer(serializers.ModelSerializer):
         validated_data['tenant'] = self.context['request'].user.employee.tenant
         instance = super(DeviceSerializer, self).create(validated_data)
 
-        id = instance.id
-        applet = WechatApplet.objects.filter(authorizer_appid=settings.WEAPP['appid']).first()
-        filename = applet.getDeviceCode(id, instance.tenant.company_no)
-        instance.wxapp_img = "{0}{1}".format(settings.MEDIA_URL,filename)
-        instance.save()
+        # id = instance.id
+        # applet = WechatApplet.objects.filter(authorizer_appid=settings.WEAPP['appid']).first()
+        # filename = applet.getDeviceCode(id, instance.tenant.company_no)
+        # instance.wxapp_img = "{0}{1}".format(settings.MEDIA_URL,filename)
+        # instance.save()
 
         return instance

+ 8 - 0
apps/tenant/employee/models.py

@@ -95,3 +95,11 @@ class Employee(models.Model):
         if id:
             rows = rows.exclude(id=id)
         return rows.count()
+
+    @staticmethod
+    def checkEmployee(tenant, id=None):
+        # 标准版 限制检修人人数为2
+        rows = Employee.objects.filter(type=Employee.EMPLOYEE, tenant=tenant)
+        if id:
+            rows = rows.exclude(id=id)
+        return rows.count() >=2 and tenant.edition < Tenant.EDITION_3

+ 2 - 4
apps/tenant/employee/serializers.py

@@ -26,8 +26,7 @@ class EmployeeSerializer(serializers.ModelSerializer):
             raise CustomError(u'已存在一个平台管理员,禁止操作!')
         #标准版 限制检修人人数为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:
+        if int(self.initial_data['type']) == Employee.EMPLOYEE and Employee.checkEmployee(self.context['request'].user.employee.tenant):
             raise CustomError(u'当前版本,仅能添加2个检修人。如有需要,请升级到更高版本!')
         # 判断用户是否已经注册登陆过
         password = None
@@ -56,8 +55,7 @@ class EmployeeSerializer(serializers.ModelSerializer):
         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:
+        if int(self.initial_data['type']) == Employee.EMPLOYEE and Employee.checkEmployee(instance.tenant, instance.id):
             raise CustomError(u'当前版本,仅能添加2个检修人。如有需要,请升级到更高版本!')
 
         username = self.initial_data['tel']