diff --git a/src/genlab_bestilling/api/constants.py b/src/genlab_bestilling/api/constants.py index 4b62197f..9fba5360 100644 --- a/src/genlab_bestilling/api/constants.py +++ b/src/genlab_bestilling/api/constants.py @@ -128,9 +128,9 @@ "rerun_date", ), "Terrestrisk": ( - "name", "genlab_id", "guid", + "name", "type.name", "species.name", "location.name", @@ -199,9 +199,9 @@ } LABEL_CSV_FIELDS_BY_AREA = { - "Akvatisk": ("fish_id", "genlab_id", "guid"), - "Elvemusling": ("fish_id", "genlab_id", "guid"), - "Terrestrisk": ("genlab_id", "guid", "name"), - "MiljøDNA": ("genlab_id", "guid", "name", "location.name"), - "default": ("genlab_id", "guid", "name"), + "Akvatisk": ("fish_id", "genlab_id", "guid", "order"), + "Elvemusling": ("fish_id", "genlab_id", "guid", "order"), + "Terrestrisk": ("genlab_id", "guid", "name", "order"), + "MiljøDNA": ("genlab_id", "guid", "name", "location.name", "order"), + "default": ("genlab_id", "guid", "name", "order"), } diff --git a/src/genlab_bestilling/api/serializers.py b/src/genlab_bestilling/api/serializers.py index 1bdf9ce8..855de4e0 100644 --- a/src/genlab_bestilling/api/serializers.py +++ b/src/genlab_bestilling/api/serializers.py @@ -166,6 +166,8 @@ def get_internal_note(self, obj: Sample) -> str: class LabelCSVSerializer(serializers.ModelSerializer): + location = LocationSerializer(allow_null=True, required=False) + class Meta: model = Sample fields = ( @@ -173,6 +175,8 @@ class Meta: "guid", "name", "fish_id", + "order", + "location", ) def get_fish_id(self, obj: Sample) -> str: diff --git a/src/genlab_bestilling/api/views.py b/src/genlab_bestilling/api/views.py index 4b78ec2a..dc428377 100644 --- a/src/genlab_bestilling/api/views.py +++ b/src/genlab_bestilling/api/views.py @@ -211,10 +211,9 @@ def get_serializer_class(self) -> type[BaseSerializer]: def get_order_id(self, queryset: QuerySet) -> str: order_id = "unknown_order_id" - first_sample = queryset.first() - if first_sample and first_sample.order and first_sample.order.id: - order_id = str(first_sample.order.id) - + order_id_value = queryset.values_list("order__id", flat=True).first() + if order_id_value: + order_id = str(order_id_value) return order_id @action(