mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-07 07:31:24 +00:00
6abd33f060
* Add "enabled" filter to template table * Cleanup * API endpoints - Add API endpoints for report snippet - List endpoint - Details endpoint * Update serializers - Add asset serializer - Update * Check for duplicate asset files - Prevent upload of duplicate asset files - Allow re-upload for same PK * Duplicate checks for ReportSnippet * Bump API version
125 lines
3.1 KiB
Python
125 lines
3.1 KiB
Python
"""API serializers for the reporting models."""
|
|
|
|
from rest_framework import serializers
|
|
|
|
import report.models
|
|
from InvenTree.serializers import (
|
|
InvenTreeAttachmentSerializerField,
|
|
InvenTreeModelSerializer,
|
|
)
|
|
|
|
|
|
class ReportSerializerBase(InvenTreeModelSerializer):
|
|
"""Base class for report serializer."""
|
|
|
|
template = InvenTreeAttachmentSerializerField(required=True)
|
|
|
|
@staticmethod
|
|
def report_fields():
|
|
"""Generic serializer fields for a report template."""
|
|
return [
|
|
'pk',
|
|
'name',
|
|
'description',
|
|
'template',
|
|
'filters',
|
|
'page_size',
|
|
'landscape',
|
|
'enabled',
|
|
]
|
|
|
|
|
|
class TestReportSerializer(ReportSerializerBase):
|
|
"""Serializer class for the TestReport model."""
|
|
|
|
class Meta:
|
|
"""Metaclass options."""
|
|
|
|
model = report.models.TestReport
|
|
fields = ReportSerializerBase.report_fields()
|
|
|
|
|
|
class BuildReportSerializer(ReportSerializerBase):
|
|
"""Serializer class for the BuildReport model."""
|
|
|
|
class Meta:
|
|
"""Metaclass options."""
|
|
|
|
model = report.models.BuildReport
|
|
fields = ReportSerializerBase.report_fields()
|
|
|
|
|
|
class BOMReportSerializer(ReportSerializerBase):
|
|
"""Serializer class for the BillOfMaterialsReport model."""
|
|
|
|
class Meta:
|
|
"""Metaclass options."""
|
|
|
|
model = report.models.BillOfMaterialsReport
|
|
fields = ReportSerializerBase.report_fields()
|
|
|
|
|
|
class PurchaseOrderReportSerializer(ReportSerializerBase):
|
|
"""Serializer class for the PurchaseOrdeReport model."""
|
|
|
|
class Meta:
|
|
"""Metaclass options."""
|
|
|
|
model = report.models.PurchaseOrderReport
|
|
fields = ReportSerializerBase.report_fields()
|
|
|
|
|
|
class SalesOrderReportSerializer(ReportSerializerBase):
|
|
"""Serializer class for the SalesOrderReport model."""
|
|
|
|
class Meta:
|
|
"""Metaclass options."""
|
|
|
|
model = report.models.SalesOrderReport
|
|
fields = ReportSerializerBase.report_fields()
|
|
|
|
|
|
class ReturnOrderReportSerializer(ReportSerializerBase):
|
|
"""Serializer class for the ReturnOrderReport model."""
|
|
|
|
class Meta:
|
|
"""Metaclass options."""
|
|
|
|
model = report.models.ReturnOrderReport
|
|
fields = ReportSerializerBase.report_fields()
|
|
|
|
|
|
class StockLocationReportSerializer(ReportSerializerBase):
|
|
"""Serializer class for the StockLocationReport model."""
|
|
|
|
class Meta:
|
|
"""Metaclass options."""
|
|
|
|
model = report.models.StockLocationReport
|
|
fields = ReportSerializerBase.report_fields()
|
|
|
|
|
|
class ReportSnippetSerializer(InvenTreeModelSerializer):
|
|
"""Serializer class for the ReportSnippet model."""
|
|
|
|
class Meta:
|
|
"""Metaclass options."""
|
|
|
|
model = report.models.ReportSnippet
|
|
|
|
fields = ['pk', 'snippet', 'description']
|
|
|
|
snippet = InvenTreeAttachmentSerializerField()
|
|
|
|
|
|
class ReportAssetSerializer(InvenTreeModelSerializer):
|
|
"""Serializer class for the ReportAsset model."""
|
|
|
|
class Meta:
|
|
"""Meta class options."""
|
|
|
|
model = report.models.ReportAsset
|
|
fields = ['pk', 'asset', 'description']
|
|
|
|
asset = InvenTreeAttachmentSerializerField()
|