From 5cfb12113e1478841f560fa550177c58739ab733 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 4 Aug 2023 16:14:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20mpointserializer=20validate=20=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=81=9Amgroup=E7=BB=91=E5=AE=9Aallocate=E5=A4=84?= =?UTF-8?q?=E7=90=862?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/serializers.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/enm/serializers.py b/apps/enm/serializers.py index 1bcfa42e..d9ac1818 100644 --- a/apps/enm/serializers.py +++ b/apps/enm/serializers.py @@ -29,11 +29,12 @@ class MpointSerializer(CustomModelSerializer): ratio_ = 0 mgroupIds = [] for i in attrs['mgroups_allocate']: - ratio_ = ratio_ + i['ratio'] - if i['mgroup'] in mgroupIds: - raise ParseError('分配集错误') - mgroupIds.append(i['mgroup']) - i['mgroup_name'] = Mgroup.objects.get(id=i['mgroup']).name + if i['mgroup']: + ratio_ = ratio_ + i['ratio'] + if i['mgroup'] in mgroupIds: + raise ParseError('分配集错误') + mgroupIds.append(i['mgroup']) + i['mgroup_name'] = Mgroup.objects.get(id=i['mgroup']).name if attrs['mgroups_allocate'] and round(ratio_, 3) != 1.0: raise ParseError('比例合计错误') return attrs