diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 02dff1d6..19b5bff3 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -433,20 +433,20 @@ class HandoverSerializer(CustomModelSerializer): source='material', read_only=True) def validate(self, attrs): - if attrs.get('wm', None): - material = attrs['wm'].material - attrs['material'] = attrs['wm'].material - attrs['batch'] = attrs['wm'].batch - attrs['send_dept'] = attrs['wm'].belong_dept - if attrs['wm'].mgroup: - attrs['send_mgroup'] = attrs['wm'].mgroup - material = attrs['material'] + material = attrs['wm'].material + attrs['material'] = attrs['wm'].material + attrs['batch'] = attrs['wm'].batch + attrs['send_dept'] = attrs['wm'].belong_dept + if attrs['wm'].mgroup: + attrs['send_mgroup'] = attrs['wm'].mgroup if material.process and material.process.into_wm_mgroup and 'recive_mgroup' not in attrs: raise ValidationError('必须指定交接工段') if 'recive_mgroup' in attrs and attrs['recive_mgroup']: attrs['recive_dept'] = attrs['recive_mgroup'].belong_dept if 'recive_dept' not in attrs and 'recive_mgroup' not in attrs: - raise ValidationError('交送车间和交送工段必须有一个') + raise ValidationError('收料车间和收料工段必须有一个') + if 'send_dept' not in attrs and 'send_mgroup' not in attrs: + raise ValidationError('送料车间和送料工段必须有一个') return attrs class Meta: @@ -455,8 +455,11 @@ class HandoverSerializer(CustomModelSerializer): read_only_fields = EXCLUDE_FIELDS + ["mlog"] extra_kwargs = { "wm": {"required": True}, + "send_dept": {"required": False}, "recive_mgroup": {"required": False}, "recive_dept": {"required": False}, + "material": {"required": False}, + "batch": {"required": False}, }