refector: HandoverSerializer validate 优化
This commit is contained in:
parent
30be6dc291
commit
a3e51a84db
|
@ -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']
|
||||
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},
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue