Fix: warn with proper error on ASN exists in trash (#8176)

This commit is contained in:
shamoon
2024-11-03 17:52:59 -08:00
committed by GitHub
parent 695967cbb2
commit ef329fc687
2 changed files with 60 additions and 0 deletions

View File

@@ -805,6 +805,22 @@ class DocumentSerializer(
doc["content"] = doc.get("content")[0:550]
return doc
def validate(self, attrs):
if (
"archive_serial_number" in attrs
and Document.deleted_objects.filter(
archive_serial_number=attrs["archive_serial_number"],
).exists()
):
raise serializers.ValidationError(
{
"archive_serial_number": [
"Document with this Archive Serial Number already exists in the trash.",
],
},
)
return super().validate(attrs)
def update(self, instance: Document, validated_data):
if "created_date" in validated_data and "created" not in validated_data:
new_datetime = datetime.datetime.combine(