feat: qctmat create update 校验唯一
This commit is contained in:
parent
bf5cfbe7e6
commit
8b22084c0a
|
|
@ -81,6 +81,30 @@ class QctMatSerializer(CustomModelSerializer):
|
|||
class Meta:
|
||||
model = QctMat
|
||||
fields = '__all__'
|
||||
|
||||
def create(self, validated_data):
|
||||
qct:Qct = validated_data.get("qct")
|
||||
use_for_in = validated_data.get("use_for_in")
|
||||
use_for_out = validated_data.get("use_for_out")
|
||||
if use_for_in:
|
||||
if QctMat.objects.filter(qct=qct, material=validated_data["material"], use_for_in=True, qct__is_deleted=False).exists():
|
||||
raise ValidationError("存在该物料的加工前检验表")
|
||||
if use_for_out:
|
||||
if QctMat.objects.filter(qct=qct, material=validated_data["material"], use_for_out=True, qct__is_deleted=False).exists():
|
||||
raise ValidationError("存在该物料的检验表")
|
||||
return super().create(validated_data)
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
qct:Qct = validated_data.get("qct")
|
||||
use_for_in = validated_data.get("use_for_in")
|
||||
use_for_out = validated_data.get("use_for_out")
|
||||
if use_for_in:
|
||||
if QctMat.objects.filter(qct=qct, material=validated_data["material"], use_for_in=True, qct__is_deleted=False).exclude(pk=instance.pk).exists():
|
||||
raise ValidationError("存在该物料的加工前检验表")
|
||||
if use_for_out:
|
||||
if QctMat.objects.filter(qct=qct, material=validated_data["material"], use_for_out=True, qct__is_deleted=False).exclude(pk=instance.pk).exists():
|
||||
raise ValidationError("存在该物料的检验表")
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
class QctDetailSerializer(CustomModelSerializer):
|
||||
qct_testitems = QctTestItemSerializer(many=True, read_only=True)
|
||||
|
|
|
|||
Loading…
Reference in New Issue