From 9362a81bc6c49acda3bd66bd23b58d8f8a17f976 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 21 Apr 2025 15:43:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=A5=E5=BF=97=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=B4=9F=E5=80=BC=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/serializers.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 0bb19ccd..d5997d15 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -212,6 +212,11 @@ class MlogbDefectSerializer(CustomModelSerializer): model = MlogbDefect fields = ["id", "defect_name", "count", "mlogb", "defect", "defect_okcate"] read_only_fields = EXCLUDE_FIELDS_BASE + ["mlogb"] + + def validate(self, attrs): + if attrs["count"] < 0: + raise serializers.ValidationError("存在负数!") + return attrs class MlogbSerializer(CustomModelSerializer): material_out_ = MaterialSimpleSerializer( @@ -675,6 +680,8 @@ class MlogbInSerializer(CustomModelSerializer): 'wm_in': {'required': True, "allow_empty": False}} def validate(self, attrs): + if attrs["count_use"] < 0 or attrs["count_pn_jgqbl"] < 0 or attrs["count_break"] < 0: + raise ParseError('存在负数!') mlog:Mlog = attrs['mlog'] is_fix = mlog.is_fix mtask: Mtask = attrs.get("mtask", None) @@ -739,6 +746,10 @@ class MlogbInUpdateSerializer(CustomModelSerializer): model = Mlogb fields = ['id', 'count_use', 'count_pn_jgqbl', 'note', 'mlogbdefect'] + def validate(self, attrs): + if attrs["count_use"] < 0 or attrs["count_pn_jgqbl"] < 0: + raise ParseError('存在负数!') + return attrs def update(self, instance, validated_data): mlog: Mlog = instance.mlog mlogbdefect = validated_data.pop("mlogbdefect", None)