diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index c528a583..85ee6d86 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -415,7 +415,9 @@ class InvenTreePart extends InvenTreeModel { } } - +/* + * Class representing an attachment file against a Part object + */ class InvenTreePartAttachment extends InvenTreeAttachment { InvenTreePartAttachment() : super(); diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index b60eb957..46b0c75a 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -601,6 +601,29 @@ class InvenTreeStockItem extends InvenTreeModel { } +/* + * Class representing an attachment file against a StockItem object + */ +class InvenTreeStockItemAttachment extends InvenTreeAttachment { + + InvenTreeStockItemAttachment() : super(); + + InvenTreeStockItemAttachment.fromJson(Map json) : super.fromJson(json); + + @override + String get REFERENCE_FIELD => "stock_item"; + + @override + String get URL => "stock/attachment/"; + + @override + InvenTreeModel createFromJson(Map json) { + return InvenTreeStockItemAttachment.fromJson(json); + } + +} + + class InvenTreeStockLocation extends InvenTreeModel { InvenTreeStockLocation() : super(); diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index 8c1a376d..d8c43adb 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -7,6 +7,7 @@ import "package:inventree/barcode.dart"; import "package:inventree/inventree/stock.dart"; import "package:inventree/inventree/part.dart"; import "package:inventree/widget/dialogs.dart"; +import "package:inventree/widget/attachment_widget.dart"; import "package:inventree/widget/location_display.dart"; import "package:inventree/widget/part_detail.dart"; import "package:inventree/widget/progress.dart"; @@ -94,6 +95,8 @@ class _StockItemDisplayState extends RefreshableState { // Part object InvenTreePart? part; + int attachmentCount = 0; + @override Future onBuild(BuildContext context) async { @@ -126,6 +129,12 @@ class _StockItemDisplayState extends RefreshableState { }); }); + attachmentCount = await InvenTreeStockItemAttachment().count( + filters: { + "stock_item": item.pk.toString() + } + ); + // Request information on labels available for this stock item if (InvenTreeAPI().pluginsEnabled()) { _getLabels(); @@ -694,6 +703,25 @@ class _StockItemDisplayState extends RefreshableState { ) ); + tiles.add( + ListTile( + title: Text(L10().attachments), + leading: FaIcon(FontAwesomeIcons.fileAlt, color: COLOR_CLICK), + trailing: attachmentCount > 0 ? Text(attachmentCount.toString()) : null, + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => AttachmentWidget( + InvenTreeStockItemAttachment(), + item.pk, + InvenTreeAPI().checkPermission("stock", "change")) + ) + ); + }, + ) + ); + return tiles; }