mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Manager for importing StockLocation data
This commit is contained in:
parent
37ab3d214d
commit
23b814569a
@ -52,10 +52,10 @@ class PartCategoryResource(ModelResource):
|
|||||||
|
|
||||||
parent = Field(attribute='parent', widget=widgets.ForeignKeyWidget(PartCategory))
|
parent = Field(attribute='parent', widget=widgets.ForeignKeyWidget(PartCategory))
|
||||||
|
|
||||||
default_location = Field(attribute='default_location', widget=widgets.ForeignKeyWidget(StockLocation))
|
|
||||||
|
|
||||||
parent_name = Field(attribute='parent__name', readonly=True)
|
parent_name = Field(attribute='parent__name', readonly=True)
|
||||||
|
|
||||||
|
default_location = Field(attribute='default_location', widget=widgets.ForeignKeyWidget(StockLocation))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PartCategory
|
model = PartCategory
|
||||||
skip_unchanged = True
|
skip_unchanged = True
|
||||||
@ -70,10 +70,8 @@ class PartCategoryResource(ModelResource):
|
|||||||
|
|
||||||
super().after_import(dataset, result, using_transactions, dry_run, **kwargs)
|
super().after_import(dataset, result, using_transactions, dry_run, **kwargs)
|
||||||
|
|
||||||
print("Rebuilding PartCategory tree")
|
# Rebuild the PartCategory tree(s)
|
||||||
# Rebuild teh PartCategory tree
|
|
||||||
PartCategory.objects.rebuild()
|
PartCategory.objects.rebuild()
|
||||||
print("Done!")
|
|
||||||
|
|
||||||
|
|
||||||
class PartCategoryAdmin(ImportExportModelAdmin):
|
class PartCategoryAdmin(ImportExportModelAdmin):
|
||||||
|
@ -1,11 +1,46 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from import_export.admin import ImportExportModelAdmin
|
from import_export.admin import ImportExportModelAdmin
|
||||||
|
from import_export.resources import ModelResource
|
||||||
|
from import_export.fields import Field
|
||||||
|
import import_export.widgets as widgets
|
||||||
|
|
||||||
from .models import StockLocation, StockItem
|
from .models import StockLocation, StockItem
|
||||||
from .models import StockItemTracking
|
from .models import StockItemTracking
|
||||||
|
|
||||||
|
|
||||||
|
class LocationResource(ModelResource):
|
||||||
|
""" Class for managing StockLocation data import/export """
|
||||||
|
|
||||||
|
parent = Field(attribute='parent', widget=widgets.ForeignKeyWidget(StockLocation))
|
||||||
|
|
||||||
|
parent_name = Field(attribute='parent__name', readonly=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = StockLocation
|
||||||
|
skip_unchanged = True
|
||||||
|
report_skipped = False
|
||||||
|
|
||||||
|
exclude = [
|
||||||
|
# Exclude MPTT internal model fields
|
||||||
|
'lft', 'rght', 'tree_id', 'level',
|
||||||
|
]
|
||||||
|
|
||||||
|
def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
|
||||||
|
|
||||||
|
super().after_import(dataset, result, using_transactions, dry_run, **kwargs)
|
||||||
|
|
||||||
|
# Rebuild the StockLocation tree(s)
|
||||||
|
StockLocation.objects.rebuild()
|
||||||
|
|
||||||
|
|
||||||
class LocationAdmin(ImportExportModelAdmin):
|
class LocationAdmin(ImportExportModelAdmin):
|
||||||
|
|
||||||
|
resource_class = LocationResource
|
||||||
|
|
||||||
list_display = ('name', 'pathstring', 'description')
|
list_display = ('name', 'pathstring', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user