2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00
* Adds API endpoint for fetching error information

* Bump API version

* Implement table for displaying server errors

* Add support for "bulk delete" in new table component

* Update API version with PR

* Fix unused variables

* Enable table sorting

* Display error details
This commit is contained in:
Oliver
2024-01-13 19:27:47 +11:00
committed by GitHub
parent 5180d86388
commit ef679b1663
9 changed files with 233 additions and 4 deletions

View File

@ -1,12 +1,15 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 160
INVENTREE_API_VERSION = 161
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v160 -> 2023-012-11 : https://github.com/inventree/InvenTree/pull/6072
v161 -> 2024-01-13 : https://github.com/inventree/InvenTree/pull/6222
- Adds API endpoint for system error information
v160 -> 2023-12-11 : https://github.com/inventree/InvenTree/pull/6072
- Adds API endpoint for allocating stock items against a sales order via barcode scan
v159 -> 2023-12-08 : https://github.com/inventree/InvenTree/pull/6056

View File

@ -10,6 +10,7 @@ from django.views.decorators.csrf import csrf_exempt
from django_q.tasks import async_task
from djmoney.contrib.exchange.models import ExchangeBackend, Rate
from error_report.models import Error
from rest_framework import permissions, serializers
from rest_framework.exceptions import NotAcceptable, NotFound
from rest_framework.permissions import IsAdminUser
@ -484,6 +485,30 @@ class CustomUnitDetail(RetrieveUpdateDestroyAPI):
permission_classes = [permissions.IsAuthenticated, IsStaffOrReadOnly]
class ErrorMessageList(BulkDeleteMixin, ListAPI):
"""List view for server error messages."""
queryset = Error.objects.all()
serializer_class = common.serializers.ErrorMessageSerializer
permission_classes = [permissions.IsAuthenticated, IsAdminUser]
filter_backends = SEARCH_ORDER_FILTER
ordering = '-when'
ordering_fields = ['when', 'info']
search_fields = ['info', 'data']
class ErrorMessageDetail(RetrieveUpdateDestroyAPI):
"""Detail view for a single error message."""
queryset = Error.objects.all()
serializer_class = common.serializers.ErrorMessageSerializer
permission_classes = [permissions.IsAuthenticated, IsAdminUser]
class FlagList(ListAPI):
"""List view for feature flags."""
@ -659,6 +684,14 @@ common_api_urls = [
re_path(r'^.*$', NewsFeedEntryList.as_view(), name='api-news-list'),
]),
),
# Error information
re_path(
r'^error-report/',
include([
path(r'<int:pk>/', ErrorMessageDetail.as_view(), name='api-error-detail'),
re_path(r'^.*$', ErrorMessageList.as_view(), name='api-error-list'),
]),
),
# Flags
path(
'flags/',

View File

@ -2,6 +2,7 @@
from django.urls import reverse
from error_report.models import Error
from flags.state import flag_state
from rest_framework import serializers
@ -302,3 +303,16 @@ class CustomUnitSerializer(InvenTreeModelSerializer):
model = common_models.CustomUnit
fields = ['pk', 'name', 'symbol', 'definition']
class ErrorMessageSerializer(InvenTreeModelSerializer):
"""DRF serializer for server error messages."""
class Meta:
"""Metaclass options for ErrorMessageSerializer."""
model = Error
fields = ['when', 'info', 'data', 'path', 'pk']
read_only_fields = ['when', 'info', 'data', 'path', 'pk']

View File

@ -337,6 +337,7 @@ class SupplierPartSerializer(InvenTreeTagModelSerializer):
def __init__(self, *args, **kwargs):
"""Initialize this serializer with extra detail fields as required."""
# Check if 'available' quantity was supplied
self.has_available_quantity = 'available' in kwargs.get('data', {})
brief = kwargs.pop('brief', False)