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:
@@ -2,7 +2,6 @@
|
||||
|
||||
import InvenTree.models
|
||||
import InvenTree.validators
|
||||
import common.validators
|
||||
from django.conf import settings
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
@@ -41,9 +40,9 @@ class Migration(migrations.Migration):
|
||||
(
|
||||
"model_type",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
blank=True, null=True,
|
||||
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",
|
||||
verbose_name="Model type",
|
||||
),
|
||||
|
||||
@@ -89,7 +89,7 @@ def copy_part_parameters(apps, schema_editor):
|
||||
checkbox=template.checkbox,
|
||||
choices=template.choices,
|
||||
selectionlist=template.selectionlist,
|
||||
model_type=''
|
||||
model_type=None
|
||||
))
|
||||
|
||||
if len(templates) > 0:
|
||||
@@ -101,13 +101,15 @@ def copy_part_parameters(apps, schema_editor):
|
||||
# Next, copy PartParameter instances to Parameter instances
|
||||
parameters = []
|
||||
|
||||
content_type = apps.get_model("contenttypes", "ContentType").objects.get(app_label='part', model='part')
|
||||
|
||||
for parameter in PartParameter.objects.all():
|
||||
# Find the corresponding ParameterTemplate
|
||||
template = ParameterTemplate.objects.get(name=parameter.template.name)
|
||||
|
||||
parameters.append(Parameter(
|
||||
template=template,
|
||||
model_type='part',
|
||||
model_type=content_type,
|
||||
model_id=parameter.part.id,
|
||||
data=parameter.data,
|
||||
data_numeric=parameter.data_numeric,
|
||||
@@ -121,7 +123,7 @@ def copy_part_parameters(apps, schema_editor):
|
||||
Parameter.objects.bulk_create(parameters)
|
||||
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):
|
||||
@@ -133,6 +135,8 @@ def copy_manufacturer_part_parameters(apps, schema_editor):
|
||||
|
||||
parameters = []
|
||||
|
||||
content_type = apps.get_model("contenttypes", "ContentType").objects.get(app_label='company', model='manufacturerpart')
|
||||
|
||||
for parameter in ManufacturerPartParameter.objects.all():
|
||||
# Find the corresponding ParameterTemplate
|
||||
template = ParameterTemplate.objects.filter(name=parameter.template.name).first()
|
||||
@@ -143,12 +147,13 @@ def copy_manufacturer_part_parameters(apps, schema_editor):
|
||||
name=parameter.name,
|
||||
description='',
|
||||
units=parameter.units,
|
||||
model_type=None,
|
||||
checkbox=False
|
||||
)
|
||||
|
||||
parameters.append(Parameter(
|
||||
template=template,
|
||||
model_type='manufacturerpart',
|
||||
model_type=content_type,
|
||||
model_id=parameter.manufacturer_part.id,
|
||||
data=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)
|
||||
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):
|
||||
|
||||
@@ -2476,8 +2476,9 @@ class ParameterTemplate(
|
||||
# TODO: Reintroduce validator for model_type
|
||||
model_type = models.ForeignKey(
|
||||
ContentType,
|
||||
on_delete=models.CASCADE,
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_('Model type'),
|
||||
help_text=_('Target model type for this parameter template'),
|
||||
)
|
||||
|
||||
@@ -298,7 +298,7 @@ class Contact(InvenTree.models.InvenTreeMetadataModel):
|
||||
|
||||
@staticmethod
|
||||
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')
|
||||
|
||||
company = models.ForeignKey(
|
||||
@@ -383,7 +383,7 @@ class Address(InvenTree.models.InvenTreeModel):
|
||||
|
||||
@staticmethod
|
||||
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')
|
||||
|
||||
company = models.ForeignKey(
|
||||
@@ -586,7 +586,7 @@ class ManufacturerPart(
|
||||
|
||||
|
||||
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.
|
||||
|
||||
@@ -891,7 +891,7 @@ class SupplierPart(
|
||||
)
|
||||
|
||||
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 = round(q, 10).normalize()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user