From 86b126f1299258b85a177c150525c93b1a85de4c Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 27 May 2026 20:01:03 +1000 Subject: [PATCH] Support "creation_date" field for StockItem (#823) Ref: https://github.com/inventree/InvenTree/pull/12011 --- lib/api.dart | 4 ++++ lib/inventree/stock.dart | 5 +++++ lib/widget/stock/stock_detail.dart | 11 +++++++++++ lib/widget/stock/stock_list.dart | 27 ++++++++++++++++++--------- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index e53c2a3e..f8fd4218 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -361,6 +361,10 @@ class InvenTreeAPI { // Ref: https://github.com/inventree/InvenTree/pull/11963 bool get supportsNewUserEndpoints => apiVersion >= 490; + // Does the server support the "creation_date" field on the StockItem model? + // Ref: https://github.com/inventree/InvenTree/pull/12011 + bool get supportsStockItemCreationDate => apiVersion >= 496; + // Cached list of plugins (refreshed when we connect to the server) List _plugins = []; diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 8ff680a1..918ff8f0 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -303,6 +303,11 @@ class InvenTreeStockItem extends InvenTreeModel { String get expiryDateString => getDateString("expiry_date"); + // Creation date + DateTime? get creationDate => getDate("creation_date"); + + String get creationDateString => getDateString("creation_date"); + // Date of last update DateTime? get updatedDate => getDate("updated"); diff --git a/lib/widget/stock/stock_detail.dart b/lib/widget/stock/stock_detail.dart index ed10212a..d10a38cb 100644 --- a/lib/widget/stock/stock_detail.dart +++ b/lib/widget/stock/stock_detail.dart @@ -732,6 +732,17 @@ class _StockItemDisplayState extends RefreshableState { ); } + if (api.supportsStockItemCreationDate && + widget.item.creationDateString.isNotEmpty) { + tiles.add( + ListTile( + title: Text(L10().creationDate), + trailing: LargeText(widget.item.creationDateString), + leading: Icon(TablerIcons.calendar_plus), + ), + ); + } + // Last update? if (widget.item.updatedDateString.isNotEmpty) { tiles.add( diff --git a/lib/widget/stock/stock_list.dart b/lib/widget/stock/stock_list.dart index d9697927..5163a127 100644 --- a/lib/widget/stock/stock_list.dart +++ b/lib/widget/stock/stock_list.dart @@ -50,15 +50,24 @@ class _PaginatedStockItemListState String get prefix => "stock_"; @override - Map get orderingOptions => { - "part__name": L10().name, - "part__IPN": L10().internalPartNumber, - "stock": L10().quantity, - "status": L10().status, - "batch": L10().batchCode, - "updated": L10().lastUpdated, - "stocktake_date": L10().lastStocktake, - }; + Map get orderingOptions { + Map options = { + "part__name": L10().name, + "part__IPN": L10().internalPartNumber, + "stock": L10().quantity, + "status": L10().status, + "batch": L10().batchCode, + "creation_date": L10().creationDate, + "updated": L10().lastUpdated, + "stocktake_date": L10().lastStocktake, + }; + + if (!InvenTreeAPI().supportsStockItemCreationDate) { + options.remove("creation_date"); + } + + return options; + } @override Map> get filterOptions {