Fix: Getting next ASN when no documents have an ASN (#5431)

* Fixes the next ASN logic to account for no ASNs yet being assigned

* Updates so the ASN will start at 1

* Do the same calculation without the branch
This commit is contained in:
Trenton H
2024-01-16 15:08:37 -08:00
committed by GitHub
parent e16645b146
commit 51dd95be3d
2 changed files with 34 additions and 9 deletions

View File

@@ -757,16 +757,12 @@ class UnifiedSearchViewSet(DocumentViewSet):
@action(detail=False, methods=["GET"], name="Get Next ASN")
def next_asn(self, request, *args, **kwargs):
return Response(
(
Document.objects.filter(archive_serial_number__gte=0)
.order_by("archive_serial_number")
.last()
.archive_serial_number
or 0
)
+ 1,
max_asn = Document.objects.aggregate(
Max("archive_serial_number", default=0),
).get(
"archive_serial_number__max",
)
return Response(max_asn + 1)
class LogViewSet(ViewSet):