From 4267b83bc5c03c94dfaaa906562ef1d4207fafbc Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Mon, 24 Jun 2024 09:49:03 +0200 Subject: [PATCH] Merge test-statistics urls --- .../build/templates/build/build_base.html | 2 +- .../InvenTree/part/templates/part/detail.html | 2 +- src/backend/InvenTree/stock/api.py | 27 +++++++++++++++---- src/frontend/src/enums/ApiEndpoints.tsx | 4 +-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/backend/InvenTree/build/templates/build/build_base.html b/src/backend/InvenTree/build/templates/build/build_base.html index 6b276721708e..de1ed826fa11 100644 --- a/src/backend/InvenTree/build/templates/build/build_base.html +++ b/src/backend/InvenTree/build/templates/build/build_base.html @@ -301,7 +301,7 @@

{% if build.part.trackable > 0 %} onPanelLoad("test-statistics", function() { - prepareTestStatisticsTable('build', '{% url "api-test-statistics/by-build" build.pk %}') + prepareTestStatisticsTable('build', '{% url "api-test-statistics-by-build" build.pk %}') }); {% endif %} {% endif %} diff --git a/src/backend/InvenTree/part/templates/part/detail.html b/src/backend/InvenTree/part/templates/part/detail.html index 5d7e924eb881..683f5004a590 100644 --- a/src/backend/InvenTree/part/templates/part/detail.html +++ b/src/backend/InvenTree/part/templates/part/detail.html @@ -769,7 +769,7 @@

{% trans "Part Manufacturers" %}

}); }); onPanelLoad("test-statistics", function() { - prepareTestStatisticsTable('part', '{% url "api-test-statistics" "by-part" part.pk %}') + prepareTestStatisticsTable('part', '{% url "api-test-statistics-by-part" part.pk %}') }); onPanelLoad("part-stock", function() { diff --git a/src/backend/InvenTree/stock/api.py b/src/backend/InvenTree/stock/api.py index df31acbe65c0..e3e8cf77b245 100644 --- a/src/backend/InvenTree/stock/api.py +++ b/src/backend/InvenTree/stock/api.py @@ -1323,10 +1323,13 @@ class TestStatistics(GenericAPIView): responses={200: StockSerializers.TestStatisticsSerializer(many=False)} ) def get(self, request, pk, *args, **kwargs): - """Return test execution count matrix broken downs by test result.""" + """Return test execution count matrix broken down by test result.""" instance = self.get_object() serializer = self.get_serializer(instance) - serializer.context['type'] = kwargs['type'] + if request.resolver_match.url_name == 'api-test-statistics-by-part': + serializer.context['type'] = 'by-part' + elif request.resolver_match.url_name == 'api-test-statistics-by-build': + serializer.context['type'] = 'by-build' serializer.context['finished_datetime_after'] = self.request.query_params.get( 'finished_datetime_after' ) @@ -1716,9 +1719,23 @@ def destroy(self, request, *args, **kwargs): test_statistics_api_urls = [ # Test statistics endpoints path( - '/', + 'by-part/', include([ - path('/', TestStatistics.as_view(), name='api-test-statistics') + path( + '/', + TestStatistics.as_view(), + name='api-test-statistics-by-part', + ) ]), - ) + ), + path( + 'by-build/', + include([ + path( + '/', + TestStatistics.as_view(), + name='api-test-statistics-by-build', + ) + ]), + ), ] diff --git a/src/frontend/src/enums/ApiEndpoints.tsx b/src/frontend/src/enums/ApiEndpoints.tsx index ad09b3e14ac9..3f9ae09a52fc 100644 --- a/src/frontend/src/enums/ApiEndpoints.tsx +++ b/src/frontend/src/enums/ApiEndpoints.tsx @@ -102,8 +102,8 @@ export enum ApiEndpoints { stock_assign = 'stock/assign/', stock_status = 'stock/status/', stock_install = 'stock/:id/install', - build_test_statistics = 'stock/test-statistics/by-build/:id', - part_test_statistics = 'stock/test-statistics/by-part/:id', + build_test_statistics = 'stock/test-statistics-by-build/:id', + part_test_statistics = 'stock/test-statistics-by-part/:id', // Generator API endpoints generate_batch_code = 'generate/batch-code/',