2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

[PUI] stock table (#8396)

* [PUI] Add extra fields to StockItemTable

* Add SKU and MPN to StockItem export data

* Enable sorting

* Bump API version
This commit is contained in:
Oliver 2024-10-31 12:34:28 +11:00 committed by GitHub
parent a826096e37
commit 8822194b0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 70 additions and 38 deletions

View File

@ -1,13 +1,17 @@
"""InvenTree API version information.""" """InvenTree API version information."""
# InvenTree API version # InvenTree API version
INVENTREE_API_VERSION = 274 INVENTREE_API_VERSION = 275
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" """Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """ INVENTREE_API_TEXT = """
v274 - 2024-10-31 : https://github.com/inventree/InvenTree/pull/8396
- Adds SKU and MPN fields to the StockItem serializer
- Additional export options for the StockItem serializer
v274 - 2024-10-29 : https://github.com/inventree/InvenTree/pull/8392 v274 - 2024-10-29 : https://github.com/inventree/InvenTree/pull/8392
- Add more detailed information to NotificationEntry API serializer - Add more detailed information to NotificationEntry API serializer

View File

@ -1175,6 +1175,7 @@ class StockList(DataExportViewMixin, ListCreateDestroyAPIView):
ordering_field_aliases = { ordering_field_aliases = {
'location': 'location__pathstring', 'location': 'location__pathstring',
'SKU': 'supplier_part__SKU', 'SKU': 'supplier_part__SKU',
'MPN': 'supplier_part__manufacturer_part__MPN',
'stock': ['quantity', 'serial_int', 'serial'], 'stock': ['quantity', 'serial_int', 'serial'],
} }
@ -1191,6 +1192,7 @@ class StockList(DataExportViewMixin, ListCreateDestroyAPIView):
'stock', 'stock',
'status', 'status',
'SKU', 'SKU',
'MPN',
] ]
ordering = ['part__name', 'quantity', 'location'] ordering = ['part__name', 'quantity', 'location']

View File

@ -340,7 +340,7 @@ class StockItemSerializer(
- Includes serialization for the item location - Includes serialization for the item location
""" """
export_exclude_fields = ['tracking_items'] export_exclude_fields = ['tags', 'tracking_items']
export_only_fields = ['part_pricing_min', 'part_pricing_max'] export_only_fields = ['part_pricing_min', 'part_pricing_max']
@ -351,7 +351,14 @@ class StockItemSerializer(
model = StockItem model = StockItem
fields = [ fields = [
'pk',
'part',
'quantity',
'serial',
'batch', 'batch',
'location',
'location_name',
'location_path',
'belongs_to', 'belongs_to',
'build', 'build',
'consumed_by', 'consumed_by',
@ -361,32 +368,23 @@ class StockItemSerializer(
'in_stock', 'in_stock',
'is_building', 'is_building',
'link', 'link',
'location',
'location_name',
'location_detail',
'location_path',
'notes', 'notes',
'owner', 'owner',
'packaging', 'packaging',
'parent', 'parent',
'part',
'part_detail',
'purchase_order', 'purchase_order',
'purchase_order_reference', 'purchase_order_reference',
'pk',
'quantity',
'sales_order', 'sales_order',
'sales_order_reference', 'sales_order_reference',
'serial',
'status', 'status',
'status_text', 'status_text',
'status_custom_key', 'status_custom_key',
'stocktake_date',
'supplier_part', 'supplier_part',
'sku', 'SKU',
'supplier_part_detail', 'MPN',
'barcode_hash', 'barcode_hash',
'updated', 'updated',
'stocktake_date',
'purchase_price', 'purchase_price',
'purchase_price_currency', 'purchase_price_currency',
'use_pack_size', 'use_pack_size',
@ -399,6 +397,10 @@ class StockItemSerializer(
'stale', 'stale',
'tracking_items', 'tracking_items',
'tags', 'tags',
# Detail fields (FK relationships)
'supplier_part_detail',
'part_detail',
'location_detail',
# Export only fields # Export only fields
'part_pricing_min', 'part_pricing_min',
'part_pricing_max', 'part_pricing_max',
@ -575,9 +577,19 @@ class StockItemSerializer(
return queryset return queryset
status_text = serializers.CharField(source='get_status_display', read_only=True) status_text = serializers.CharField(
source='get_status_display', read_only=True, label=_('Status')
)
sku = serializers.CharField(source='supplier_part.SKU', read_only=True) SKU = serializers.CharField(
source='supplier_part.SKU', read_only=True, label=_('Supplier Part Number')
)
MPN = serializers.CharField(
source='supplier_part.manufacturer_part.MPN',
read_only=True,
label=_('Manufacturer Part Number'),
)
# Optional detail fields, which can be appended via query parameters # Optional detail fields, which can be appended via query parameters
supplier_part_detail = company_serializers.SupplierPartSerializer( supplier_part_detail = company_serializers.SupplierPartSerializer(
@ -588,6 +600,7 @@ class StockItemSerializer(
many=False, many=False,
read_only=True, read_only=True,
) )
part_detail = part_serializers.PartBriefSerializer( part_detail = part_serializers.PartBriefSerializer(
source='part', many=False, read_only=True source='part', many=False, read_only=True
) )

View File

@ -217,24 +217,26 @@ function stockItemTableColumns(): TableColumn[] {
LocationColumn({ LocationColumn({
accessor: 'location_detail' accessor: 'location_detail'
}), }),
DateColumn({ {
accessor: 'stocktake_date', accessor: 'purchase_order',
title: t`Stocktake Date`, title: t`Purchase Order`,
render: (record: any) => {
return record.purchase_order_reference;
}
},
{
accessor: 'SKU',
title: t`Supplier Part`,
sortable: true sortable: true
}), },
DateColumn({ {
title: t`Expiry Date`, accessor: 'MPN',
accessor: 'expiry_date', title: t`Manufacturer Part`,
hidden: !useGlobalSettingsState.getState().isSet('STOCK_ENABLE_EXPIRY') sortable: true
}), },
DateColumn({
title: t`Last Updated`,
accessor: 'updated'
}),
// TODO: purchase order
// TODO: Supplier part
{ {
accessor: 'purchase_price', accessor: 'purchase_price',
title: t`Unit Price`,
sortable: true, sortable: true,
switchable: true, switchable: true,
render: (record: any) => render: (record: any) =>
@ -242,10 +244,6 @@ function stockItemTableColumns(): TableColumn[] {
currency: record.purchase_price_currency currency: record.purchase_price_currency
}) })
}, },
{
accessor: 'packaging',
sortable: true
},
{ {
accessor: 'stock_value', accessor: 'stock_value',
title: t`Stock Value`, title: t`Stock Value`,
@ -264,9 +262,24 @@ function stockItemTableColumns(): TableColumn[] {
} }
}, },
{ {
accessor: 'notes', accessor: 'packaging',
sortable: false sortable: true
} },
DateColumn({
title: t`Expiry Date`,
accessor: 'expiry_date',
hidden: !useGlobalSettingsState.getState().isSet('STOCK_ENABLE_EXPIRY')
}),
DateColumn({
title: t`Last Updated`,
accessor: 'updated'
}),
DateColumn({
accessor: 'stocktake_date',
title: t`Stocktake Date`,
sortable: true
})
]; ];
} }