Skip to content

Commit

Permalink
Remove DataImportMixin class
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Dec 24, 2024
1 parent bc47bc5 commit 4359870
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 77 deletions.
55 changes: 0 additions & 55 deletions src/backend/InvenTree/InvenTree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,61 +225,6 @@ def set_metadata(
self.save()


class DataImportMixin:
"""Model mixin class which provides support for 'data import' functionality.
Models which implement this mixin should provide information on the fields available for import
"""

# TODO: This mixin should be removed after https://github.com/inventree/InvenTree/pull/6911 is implemented
# TODO: This approach to data import functionality is *outdated*

# Define a map of fields available for import
IMPORT_FIELDS = {}

@classmethod
def get_import_fields(cls):
"""Return all available import fields.
Where information on a particular field is not explicitly provided,
introspect the base model to (attempt to) find that information.
"""
fields = cls.IMPORT_FIELDS

for name, field in fields.items():
# Attempt to extract base field information from the model
base_field = None

for f in cls._meta.fields:
if f.name == name:
base_field = f
break

if base_field:
if 'label' not in field:
field['label'] = base_field.verbose_name

if 'help_text' not in field:
field['help_text'] = base_field.help_text

fields[name] = field

return fields

@classmethod
def get_required_import_fields(cls):
"""Return all *required* import fields."""
fields = {}

for name, field in cls.get_import_fields().items():
required = field.get('required', False)

if required:
fields[name] = field

return fields


class ReferenceIndexingMixin(models.Model):
"""A mixin for keeping track of numerical copies of the "reference" field.
Expand Down
23 changes: 1 addition & 22 deletions src/backend/InvenTree/part/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4089,11 +4089,7 @@ def clean(self):
)


class BomItem(
InvenTree.models.DataImportMixin,
InvenTree.models.MetadataMixin,
InvenTree.models.InvenTreeModel,
):
class BomItem(InvenTree.models.MetadataMixin, InvenTree.models.InvenTreeModel):
"""A BomItem links a part to its component items.
A part can have a BOM (bill of materials) which defines
Expand All @@ -4113,23 +4109,6 @@ class BomItem(
allow_variants: Stock for part variants can be substituted for this BomItem
"""

# Fields available for bulk import
IMPORT_FIELDS = {
'quantity': {'required': True},
'reference': {},
'overage': {},
'allow_variants': {},
'inherited': {},
'optional': {},
'consumable': {},
'note': {},
'part': {'label': _('Part'), 'help_text': _('Part ID or part name')},
'part_id': {'label': _('Part ID'), 'help_text': _('Unique part ID value')},
'part_name': {'label': _('Part Name'), 'help_text': _('Part name')},
'part_ipn': {'label': _('Part IPN'), 'help_text': _('Part IPN value')},
'level': {'label': _('Level'), 'help_text': _('BOM level')},
}

class Meta:
"""Metaclass providing extra model definition."""

Expand Down

0 comments on commit 4359870

Please sign in to comment.