feat: 校验SupplierAudit供应商名称已存在
This commit is contained in:
parent
8af5be4429
commit
72f8637e19
|
|
@ -1,7 +1,7 @@
|
|||
from rest_framework import serializers
|
||||
from apps.utils.serializers import CustomModelSerializer
|
||||
from apps.utils.constants import EXCLUDE_FIELDS_DEPT, EXCLUDE_FIELDS_BASE, EXCLUDE_FIELDS
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.exceptions import ValidationError, ParseError
|
||||
|
||||
from apps.pum.models import Supplier, PuPlan, PuPlanItem, PuOrder, PuOrderItem, SupplierAudit
|
||||
from apps.mtm.serializers import MaterialSerializer, MaterialSimpleSerializer
|
||||
|
|
@ -151,4 +151,10 @@ class SupplierAuditSerializer(CustomModelSerializer):
|
|||
class Meta:
|
||||
model = SupplierAudit
|
||||
fields = "__all__"
|
||||
read_only_fields = EXCLUDE_FIELDS_BASE + ['ticket']
|
||||
read_only_fields = EXCLUDE_FIELDS_BASE + ['ticket']
|
||||
|
||||
def create(self, validated_data):
|
||||
name = validated_data["name"]
|
||||
if Supplier.objects.filter(name=name).exists():
|
||||
raise ParseError('供应商名称已存在')
|
||||
return super().create(validated_data)
|
||||
Loading…
Reference in New Issue