Fix stocktake export

- Exclude MPTT fields
- Fix foreignkey field references
This commit is contained in:
Oliver Walters 2020-08-21 20:08:47 +10:00
parent 25cced3b90
commit 59b3d8b5bc

View File

@ -13,7 +13,7 @@ from .models import StockItemTracking
from .models import StockItemTestResult from .models import StockItemTestResult
from build.models import Build from build.models import Build
from company.models import SupplierPart from company.models import Company, SupplierPart
from order.models import PurchaseOrder, SalesOrder from order.models import PurchaseOrder, SalesOrder
from part.models import Part from part.models import Part
@ -59,12 +59,14 @@ class StockItemResource(ModelResource):
# Custom manaegrs for ForeignKey fields # Custom manaegrs for ForeignKey fields
part = Field(attribute='part', widget=widgets.ForeignKeyWidget(Part)) part = Field(attribute='part', widget=widgets.ForeignKeyWidget(Part))
part_name = Field(attribute='part__full_ame', readonly=True) part_name = Field(attribute='part__full_name', readonly=True)
supplier_part = Field(attribute='supplier_part', widget=widgets.ForeignKeyWidget(SupplierPart)) supplier_part = Field(attribute='supplier_part', widget=widgets.ForeignKeyWidget(SupplierPart))
supplier = Field(attribute='supplier_part__supplier__id', readonly=True) supplier = Field(attribute='supplier_part__supplier__id', readonly=True)
customer = Field(attribute='customer', widget=widgets.ForeignKeyWidget(Company))
supplier_name = Field(attribute='supplier_part__supplier__name', readonly=True) supplier_name = Field(attribute='supplier_part__supplier__name', readonly=True)
status_label = Field(attribute='status_label', readonly=True) status_label = Field(attribute='status_label', readonly=True)
@ -77,6 +79,8 @@ class StockItemResource(ModelResource):
build = Field(attribute='build', widget=widgets.ForeignKeyWidget(Build)) build = Field(attribute='build', widget=widgets.ForeignKeyWidget(Build))
parent = Field(attribute='parent', widget=widgets.ForeignKeyWidget(StockItem))
sales_order = Field(attribute='sales_order', widget=widgets.ForeignKeyWidget(SalesOrder)) sales_order = Field(attribute='sales_order', widget=widgets.ForeignKeyWidget(SalesOrder))
build_order = Field(attribute='build_order', widget=widgets.ForeignKeyWidget(Build)) build_order = Field(attribute='build_order', widget=widgets.ForeignKeyWidget(Build))
@ -101,6 +105,11 @@ class StockItemResource(ModelResource):
report_skipped = False report_skipped = False
clean_model_instance = True clean_model_instance = True
exclude = [
# Exclude MPTT internal model fields
'lft', 'rght', 'tree_id', 'level',
]
class StockItemAdmin(ImportExportModelAdmin): class StockItemAdmin(ImportExportModelAdmin):