mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-16 09:18:10 +00:00
Remove serializer
This commit is contained in:
@@ -2445,6 +2445,33 @@ class Part(
|
|||||||
if len(templates) > 0:
|
if len(templates) > 0:
|
||||||
PartTestTemplate.objects.bulk_create(templates)
|
PartTestTemplate.objects.bulk_create(templates)
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
|
def copy_category_parameters(self, category: PartCategory):
|
||||||
|
"""Copy parameter templates from the specified PartCategory.
|
||||||
|
|
||||||
|
This function is normally called when the Part is first created.
|
||||||
|
"""
|
||||||
|
# TODO: https://github.com/inventree/InvenTree/pull/10699
|
||||||
|
# TODO: Reimplement this
|
||||||
|
# for template in templates:
|
||||||
|
# # First ensure that the part doesn't have that parameter
|
||||||
|
# if PartParameter.objects.filter(
|
||||||
|
# part=instance, template=template.parameter_template
|
||||||
|
# ).exists():
|
||||||
|
# continue
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# PartParameter.create(
|
||||||
|
# part=instance,
|
||||||
|
# template=template.parameter_template,
|
||||||
|
# data=template.default_value,
|
||||||
|
# save=True,
|
||||||
|
# )
|
||||||
|
# except IntegrityError:
|
||||||
|
# logger.exception(
|
||||||
|
# 'Could not create new PartParameter for part %s', instance
|
||||||
|
# )
|
||||||
|
|
||||||
def getTestTemplates(
|
def getTestTemplates(
|
||||||
self, required=None, include_parent: bool = True, enabled=None
|
self, required=None, include_parent: bool = True, enabled=None
|
||||||
) -> QuerySet[PartTestTemplate]:
|
) -> QuerySet[PartTestTemplate]:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from decimal import Decimal
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
from django.db import IntegrityError, models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import ExpressionWrapper, F, Q
|
from django.db.models import ExpressionWrapper, F, Q
|
||||||
from django.db.models.functions import Coalesce, Greatest
|
from django.db.models.functions import Coalesce, Greatest
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
@@ -49,8 +49,6 @@ from .models import (
|
|||||||
PartCategory,
|
PartCategory,
|
||||||
PartCategoryParameterTemplate,
|
PartCategoryParameterTemplate,
|
||||||
PartInternalPriceBreak,
|
PartInternalPriceBreak,
|
||||||
PartParameter,
|
|
||||||
PartParameterTemplate,
|
|
||||||
PartPricing,
|
PartPricing,
|
||||||
PartRelated,
|
PartRelated,
|
||||||
PartSellPriceBreak,
|
PartSellPriceBreak,
|
||||||
@@ -284,40 +282,6 @@ class PartThumbSerializerUpdate(InvenTree.serializers.InvenTreeModelSerializer):
|
|||||||
image = InvenTree.serializers.InvenTreeAttachmentSerializerField(required=True)
|
image = InvenTree.serializers.InvenTreeAttachmentSerializerField(required=True)
|
||||||
|
|
||||||
|
|
||||||
@register_importer()
|
|
||||||
class PartParameterTemplateSerializer(
|
|
||||||
DataImportExportSerializerMixin, InvenTree.serializers.InvenTreeModelSerializer
|
|
||||||
):
|
|
||||||
"""JSON serializer for the PartParameterTemplate model."""
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
"""Metaclass defining serializer fields."""
|
|
||||||
|
|
||||||
model = PartParameterTemplate
|
|
||||||
fields = [
|
|
||||||
'pk',
|
|
||||||
'name',
|
|
||||||
'units',
|
|
||||||
'description',
|
|
||||||
'parts',
|
|
||||||
'checkbox',
|
|
||||||
'choices',
|
|
||||||
'selectionlist',
|
|
||||||
]
|
|
||||||
|
|
||||||
parts = serializers.IntegerField(
|
|
||||||
read_only=True,
|
|
||||||
allow_null=True,
|
|
||||||
label=_('Parts'),
|
|
||||||
help_text=_('Number of parts using this template'),
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def annotate_queryset(queryset):
|
|
||||||
"""Annotate the queryset with the number of parts which use each parameter template."""
|
|
||||||
return queryset.annotate(parts=SubqueryCount('instances'))
|
|
||||||
|
|
||||||
|
|
||||||
class PartBriefSerializer(
|
class PartBriefSerializer(
|
||||||
InvenTree.serializers.FilterableSerializerMixin,
|
InvenTree.serializers.FilterableSerializerMixin,
|
||||||
InvenTree.serializers.InvenTreeModelSerializer,
|
InvenTree.serializers.InvenTreeModelSerializer,
|
||||||
@@ -1066,31 +1030,7 @@ class PartSerializer(
|
|||||||
# Duplicate parameter data from part category (and parents)
|
# Duplicate parameter data from part category (and parents)
|
||||||
if copy_category_parameters and instance.category is not None:
|
if copy_category_parameters and instance.category is not None:
|
||||||
# Get flattened list of parent categories
|
# Get flattened list of parent categories
|
||||||
categories = instance.category.get_ancestors(include_self=True)
|
instance.copy_category_parameters(instance.category)
|
||||||
|
|
||||||
# All parameter templates within these categories
|
|
||||||
templates = PartCategoryParameterTemplate.objects.filter(
|
|
||||||
category__in=categories
|
|
||||||
)
|
|
||||||
|
|
||||||
for template in templates:
|
|
||||||
# First ensure that the part doesn't have that parameter
|
|
||||||
if PartParameter.objects.filter(
|
|
||||||
part=instance, template=template.parameter_template
|
|
||||||
).exists():
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
PartParameter.create(
|
|
||||||
part=instance,
|
|
||||||
template=template.parameter_template,
|
|
||||||
data=template.default_value,
|
|
||||||
save=True,
|
|
||||||
)
|
|
||||||
except IntegrityError:
|
|
||||||
logger.exception(
|
|
||||||
'Could not create new PartParameter for part %s', instance
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create initial stock entry
|
# Create initial stock entry
|
||||||
if initial_stock:
|
if initial_stock:
|
||||||
@@ -1818,13 +1758,14 @@ class CategoryParameterTemplateSerializer(
|
|||||||
'category',
|
'category',
|
||||||
'category_detail',
|
'category_detail',
|
||||||
'parameter_template',
|
'parameter_template',
|
||||||
'parameter_template_detail',
|
# 'parameter_template_detail',
|
||||||
'default_value',
|
'default_value',
|
||||||
]
|
]
|
||||||
|
|
||||||
parameter_template_detail = PartParameterTemplateSerializer(
|
# TODO: Re-implement this, but point to the ParameterTemplate model
|
||||||
source='parameter_template', many=False, read_only=True
|
# parameter_template_detail = PartParameterTemplateSerializer(
|
||||||
)
|
# source='parameter_template', many=False, read_only=True
|
||||||
|
# )
|
||||||
|
|
||||||
category_detail = CategorySerializer(
|
category_detail = CategorySerializer(
|
||||||
source='category', many=False, read_only=True, allow_null=True
|
source='category', many=False, read_only=True, allow_null=True
|
||||||
|
|||||||
Reference in New Issue
Block a user