2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-16 17:28:11 +00:00

Fixes for table structure

This commit is contained in:
Oliver Walters
2025-11-24 12:44:56 +00:00
parent 1c7789a286
commit 019494420a
4 changed files with 18 additions and 13 deletions

View File

@@ -2,7 +2,6 @@
import InvenTree.models import InvenTree.models
import InvenTree.validators import InvenTree.validators
import common.validators
from django.conf import settings from django.conf import settings
import django.core.validators import django.core.validators
from django.db import migrations, models from django.db import migrations, models
@@ -41,9 +40,9 @@ class Migration(migrations.Migration):
( (
"model_type", "model_type",
models.ForeignKey( models.ForeignKey(
blank=True, blank=True, null=True,
help_text="Target model type for this parameter template", help_text="Target model type for this parameter template",
on_delete=django.db.models.deletion.CASCADE, on_delete=django.db.models.deletion.SET_NULL,
to="contenttypes.contenttype", to="contenttypes.contenttype",
verbose_name="Model type", verbose_name="Model type",
), ),

View File

@@ -89,7 +89,7 @@ def copy_part_parameters(apps, schema_editor):
checkbox=template.checkbox, checkbox=template.checkbox,
choices=template.choices, choices=template.choices,
selectionlist=template.selectionlist, selectionlist=template.selectionlist,
model_type='' model_type=None
)) ))
if len(templates) > 0: if len(templates) > 0:
@@ -101,13 +101,15 @@ def copy_part_parameters(apps, schema_editor):
# Next, copy PartParameter instances to Parameter instances # Next, copy PartParameter instances to Parameter instances
parameters = [] parameters = []
content_type = apps.get_model("contenttypes", "ContentType").objects.get(app_label='part', model='part')
for parameter in PartParameter.objects.all(): for parameter in PartParameter.objects.all():
# Find the corresponding ParameterTemplate # Find the corresponding ParameterTemplate
template = ParameterTemplate.objects.get(name=parameter.template.name) template = ParameterTemplate.objects.get(name=parameter.template.name)
parameters.append(Parameter( parameters.append(Parameter(
template=template, template=template,
model_type='part', model_type=content_type,
model_id=parameter.part.id, model_id=parameter.part.id,
data=parameter.data, data=parameter.data,
data_numeric=parameter.data_numeric, data_numeric=parameter.data_numeric,
@@ -121,7 +123,7 @@ def copy_part_parameters(apps, schema_editor):
Parameter.objects.bulk_create(parameters) Parameter.objects.bulk_create(parameters)
print(f"\nMigrated {len(parameters)} PartParameter instances.") print(f"\nMigrated {len(parameters)} PartParameter instances.")
assert Parameter.objects.filter(model_type='part').count() == len(parameters) assert Parameter.objects.filter(model_type=content_type).count() == len(parameters)
def copy_manufacturer_part_parameters(apps, schema_editor): def copy_manufacturer_part_parameters(apps, schema_editor):
@@ -133,6 +135,8 @@ def copy_manufacturer_part_parameters(apps, schema_editor):
parameters = [] parameters = []
content_type = apps.get_model("contenttypes", "ContentType").objects.get(app_label='company', model='manufacturerpart')
for parameter in ManufacturerPartParameter.objects.all(): for parameter in ManufacturerPartParameter.objects.all():
# Find the corresponding ParameterTemplate # Find the corresponding ParameterTemplate
template = ParameterTemplate.objects.filter(name=parameter.template.name).first() template = ParameterTemplate.objects.filter(name=parameter.template.name).first()
@@ -143,12 +147,13 @@ def copy_manufacturer_part_parameters(apps, schema_editor):
name=parameter.name, name=parameter.name,
description='', description='',
units=parameter.units, units=parameter.units,
model_type=None,
checkbox=False checkbox=False
) )
parameters.append(Parameter( parameters.append(Parameter(
template=template, template=template,
model_type='manufacturerpart', model_type=content_type,
model_id=parameter.manufacturer_part.id, model_id=parameter.manufacturer_part.id,
data=parameter.value, data=parameter.value,
data_numeric=convert_to_numeric_value(parameter.value), data_numeric=convert_to_numeric_value(parameter.value),
@@ -159,7 +164,7 @@ def copy_manufacturer_part_parameters(apps, schema_editor):
Parameter.objects.bulk_create(parameters) Parameter.objects.bulk_create(parameters)
print(f"\nMigrated {len(parameters)} ManufacturerPartParameter instances.") print(f"\nMigrated {len(parameters)} ManufacturerPartParameter instances.")
assert Parameter.objects.filter(model_type='manufacturerpart').count() == len(parameters) assert Parameter.objects.filter(model_type=content_type).count() == len(parameters)
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@@ -2476,8 +2476,9 @@ class ParameterTemplate(
# TODO: Reintroduce validator for model_type # TODO: Reintroduce validator for model_type
model_type = models.ForeignKey( model_type = models.ForeignKey(
ContentType, ContentType,
on_delete=models.CASCADE, on_delete=models.SET_NULL,
blank=True, blank=True,
null=True,
verbose_name=_('Model type'), verbose_name=_('Model type'),
help_text=_('Target model type for this parameter template'), help_text=_('Target model type for this parameter template'),
) )

View File

@@ -298,7 +298,7 @@ class Contact(InvenTree.models.InvenTreeMetadataModel):
@staticmethod @staticmethod
def get_api_url(): def get_api_url():
"""Return the API URL associated with the Contcat model.""" """Return the API URL associated with the Contact model."""
return reverse('api-contact-list') return reverse('api-contact-list')
company = models.ForeignKey( company = models.ForeignKey(
@@ -383,7 +383,7 @@ class Address(InvenTree.models.InvenTreeModel):
@staticmethod @staticmethod
def get_api_url(): def get_api_url():
"""Return the API URL associated with the Contcat model.""" """Return the API URL associated with the Contact model."""
return reverse('api-address-list') return reverse('api-address-list')
company = models.ForeignKey( company = models.ForeignKey(
@@ -586,7 +586,7 @@ class ManufacturerPart(
class ManufacturerPartParameter(InvenTree.models.InvenTreeModel): class ManufacturerPartParameter(InvenTree.models.InvenTreeModel):
"""A ManufacturerPartParameter represents a key:value parameter for a MnaufacturerPart. """A ManufacturerPartParameter represents a key:value parameter for a ManufacturerPart.
This is used to represent parameters / properties for a particular manufacturer part. This is used to represent parameters / properties for a particular manufacturer part.
@@ -891,7 +891,7 @@ class SupplierPart(
) )
def base_quantity(self, quantity=1) -> Decimal: def base_quantity(self, quantity=1) -> Decimal:
"""Calculate the base unit quantiy for a given quantity.""" """Calculate the base unit quantity for a given quantity."""
q = Decimal(quantity) * Decimal(self.pack_quantity_native) q = Decimal(quantity) * Decimal(self.pack_quantity_native)
q = round(q, 10).normalize() q = round(q, 10).normalize()