2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-16 04:05:28 +00:00

Supplier part support (#253)

* Bump version and release noes

* Add barebone list and detail widgets for the SupplierPart model

* Launch into SupplierPartList from CompanyDetail

* Update StockDetail widget

* Fixes for SupplierPart model

* Add images to supplier part list

* Add search functionality to SupplierPart list

* Added details to SupplierPartDetail widget

* Link through to supplier company

* Add some more details

* Adds ability to edit SupplierPart information

* Navigate to supplier part list from part detail page

* Display supplier part information on stock item detail page

* Add barcode scan response for SupplierPart

* Refactor barcode scanning code

* Navigate to supplier part detail from stock item page

* Support custom barcode for SupplierPart via app

* Cleanup comment

* linting

* Fix override

* Enable display of supplier list on home screen

* Code cleanup

* Update release noets
This commit is contained in:
Oliver
2023-02-04 09:05:36 +11:00
committed by GitHub
parent ce37d0e757
commit 15bf109296
22 changed files with 798 additions and 295 deletions

View File

@ -4,8 +4,16 @@ import "package:font_awesome_flutter/font_awesome_flutter.dart";
import "package:inventree/app_colors.dart";
import "package:inventree/barcode.dart";
import "package:inventree/l10.dart";
import "package:inventree/api.dart";
import "package:inventree/api_form.dart";
import "package:inventree/preferences.dart";
import "package:inventree/inventree/company.dart";
import "package:inventree/inventree/stock.dart";
import "package:inventree/inventree/part.dart";
import "package:inventree/widget/supplier_part_detail.dart";
import "package:inventree/widget/dialogs.dart";
import "package:inventree/widget/attachment_widget.dart";
import "package:inventree/widget/location_display.dart";
@ -16,10 +24,6 @@ import "package:inventree/widget/snacks.dart";
import "package:inventree/widget/stock_item_history.dart";
import "package:inventree/widget/stock_item_test_results.dart";
import "package:inventree/widget/stock_notes.dart";
import "package:inventree/l10.dart";
import "package:inventree/api.dart";
import "package:inventree/api_form.dart";
import "package:inventree/preferences.dart";
class StockDetailWidget extends StatefulWidget {
@ -29,13 +33,13 @@ class StockDetailWidget extends StatefulWidget {
final InvenTreeStockItem item;
@override
_StockItemDisplayState createState() => _StockItemDisplayState(item);
_StockItemDisplayState createState() => _StockItemDisplayState();
}
class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
_StockItemDisplayState(this.item);
_StockItemDisplayState();
@override
String getAppBarTitle(BuildContext context) => L10().stockItem;
@ -62,7 +66,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
icon: FaIcon(FontAwesomeIcons.searchLocation),
tooltip: L10().locateItem,
onPressed: () async {
InvenTreeAPI().locateItemOrLocation(context, item: item.pk);
InvenTreeAPI().locateItemOrLocation(context, item: widget.item.pk);
},
)
);
@ -82,12 +86,9 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}
Future<void> _openInvenTreePage() async {
item.goToInvenTreePage();
widget.item.goToInvenTreePage();
}
// StockItem object
final InvenTreeStockItem item;
// Is label printing enabled for this StockItem?
// This will be determined when the widget is loaded
List<Map<String, dynamic>> labels = [];
@ -111,7 +112,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
stockShowHistory = await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_HISTORY, false) as bool;
final bool result = item.pk > 0 && await item.reload();
final bool result = widget.item.pk > 0 && await widget.item.reload();
// Could not load this stock item for some reason
// Perhaps it has been depleted?
@ -120,10 +121,10 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}
// Request part information
part = await InvenTreePart().get(item.partId) as InvenTreePart?;
part = await InvenTreePart().get(widget.item.partId) as InvenTreePart?;
// Request test results (async)
item.getTestResults().then((value) {
widget.item.getTestResults().then((value) {
if (mounted) {
setState(() {
@ -135,7 +136,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
// Request the number of attachments
InvenTreeStockItemAttachment().count(
filters: {
"stock_item": item.pk.toString()
"stock_item": widget.item.pk.toString()
}
).then((int value) {
@ -165,7 +166,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
"/label/stock/",
params: {
"enabled": "true",
"item": "${item.pk}",
"item": "${widget.item.pk}",
},
).then((APIResponse response) {
if (response.isValid() && response.statusCode == 200) {
@ -190,7 +191,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
L10().stockItemDeleteConfirm,
icon: FontAwesomeIcons.trashAlt,
onAccept: () async {
final bool result = await item.delete();
final bool result = await widget.item.delete();
if (result) {
Navigator.of(context).pop();
@ -264,7 +265,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
String pluginKey = (data["plugin"] ?? "") as String;
if (labelId != -1 && pluginKey.isNotEmpty) {
String url = "/label/stock/${labelId}/print/?item=${item.pk}&plugin=${pluginKey}";
String url = "/label/stock/${labelId}/print/?item=${widget.item.pk}&plugin=${pluginKey}";
InvenTreeAPI().get(url).then((APIResponse response) {
if (response.isValid() && response.statusCode == 200) {
@ -298,7 +299,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
fields.remove("serial");
}
item.editForm(
widget.item.editForm(
context,
L10().editItem,
fields: fields,
@ -320,7 +321,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
"value": widget.item.pk,
},
"quantity": {
"parent": "items",
@ -361,7 +362,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
"value": widget.item.pk,
},
"quantity": {
"parent": "items",
@ -392,12 +393,12 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
"value": widget.item.pk,
},
"quantity": {
"parent": "items",
"nested": true,
"value": item.quantity,
"value": widget.item.quantity,
},
"notes": {},
};
@ -426,18 +427,18 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
"value": widget.item.pk,
},
"quantity": {
"parent": "items",
"nested": true,
"value": item.quantity,
"value": widget.item.quantity,
},
"location": {},
"notes": {},
};
if (item.isSerialized()) {
if (widget.item.isSerialized()) {
// Prevent editing of 'quantity' field if the item is serialized
fields["quantity"]["hidden"] = true;
}
@ -459,20 +460,20 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
Widget headerTile() {
return Card(
child: ListTile(
title: Text("${item.partName}"),
subtitle: Text("${item.partDescription}"),
leading: InvenTreeAPI().getImage(item.partImage),
title: Text("${widget.item.partName}"),
subtitle: Text("${widget.item.partDescription}"),
leading: InvenTreeAPI().getImage(widget.item.partImage),
trailing: Text(
item.statusLabel(),
widget.item.statusLabel(),
style: TextStyle(
color: item.statusColor
color: widget.item.statusColor
)
),
onTap: () async {
if (item.partId > 0) {
if (widget.item.partId > 0) {
showLoadingOverlay(context);
var part = await InvenTreePart().get(item.partId);
var part = await InvenTreePart().get(widget.item.partId);
hideLoadingOverlay();
if (part is InvenTreePart) {
@ -501,39 +502,39 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}
// Quantity information
if (item.isSerialized()) {
if (widget.item.isSerialized()) {
tiles.add(
ListTile(
title: Text(L10().serialNumber),
leading: FaIcon(FontAwesomeIcons.hashtag),
trailing: Text("${item.serialNumber}"),
trailing: Text("${widget.item.serialNumber}"),
)
);
} else {
tiles.add(
ListTile(
title: item.allocated > 0 ? Text(L10().quantityAvailable) : Text(L10().quantity),
title: widget.item.allocated > 0 ? Text(L10().quantityAvailable) : Text(L10().quantity),
leading: FaIcon(FontAwesomeIcons.cubes),
trailing: Text("${item.quantityString()}"),
trailing: Text("${widget.item.quantityString()}"),
)
);
}
// Location information
if ((item.locationId > 0) && (item.locationName.isNotEmpty)) {
if ((widget.item.locationId > 0) && (widget.item.locationName.isNotEmpty)) {
tiles.add(
ListTile(
title: Text(L10().stockLocation),
subtitle: Text("${item.locationPathString}"),
subtitle: Text("${widget.item.locationPathString}"),
leading: FaIcon(
FontAwesomeIcons.mapMarkerAlt,
color: COLOR_CLICK,
),
onTap: () async {
if (item.locationId > 0) {
if (widget.item.locationId > 0) {
showLoadingOverlay(context);
var loc = await InvenTreeStockLocation().get(item.locationId);
var loc = await InvenTreeStockLocation().get(widget.item.locationId);
hideLoadingOverlay();
if (loc is InvenTreeStockLocation) {
@ -554,7 +555,35 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
);
}
if (item.isBuilding) {
// Supplier part information (if available)
if (widget.item.supplierPartId > 0) {
tiles.add(
ListTile(
title: Text(L10().supplierPart),
subtitle: Text(widget.item.supplierSKU),
leading: FaIcon(FontAwesomeIcons.building, color: COLOR_CLICK),
trailing: InvenTreeAPI().getImage(
widget.item.supplierImage,
width: 40,
height: 40,
),
onTap: () async {
showLoadingOverlay(context);
var sp = await InvenTreeSupplierPart().get(
widget.item.supplierPartId);
hideLoadingOverlay();
if (sp is InvenTreeSupplierPart) {
Navigator.push(
context, MaterialPageRoute(
builder: (context) => SupplierPartDetailWidget(sp))
);
}
}
)
);
}
if (widget.item.isBuilding) {
tiles.add(
ListTile(
title: Text(L10().inProduction),
@ -567,88 +596,72 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
);
}
if (item.batch.isNotEmpty) {
if (widget.item.batch.isNotEmpty) {
tiles.add(
ListTile(
title: Text(L10().batchCode),
subtitle: Text(item.batch),
subtitle: Text(widget.item.batch),
leading: FaIcon(FontAwesomeIcons.layerGroup),
)
);
}
if (item.packaging.isNotEmpty) {
if (widget.item.packaging.isNotEmpty) {
tiles.add(
ListTile(
title: Text(L10().packaging),
subtitle: Text(item.packaging),
subtitle: Text(widget.item.packaging),
leading: FaIcon(FontAwesomeIcons.box),
)
);
}
// Last update?
if (item.updatedDateString.isNotEmpty) {
if (widget.item.updatedDateString.isNotEmpty) {
tiles.add(
ListTile(
title: Text(L10().lastUpdated),
subtitle: Text(item.updatedDateString),
subtitle: Text(widget.item.updatedDateString),
leading: FaIcon(FontAwesomeIcons.calendarAlt)
)
);
}
// Stocktake?
if (item.stocktakeDateString.isNotEmpty) {
if (widget.item.stocktakeDateString.isNotEmpty) {
tiles.add(
ListTile(
title: Text(L10().lastStocktake),
subtitle: Text(item.stocktakeDateString),
subtitle: Text(widget.item.stocktakeDateString),
leading: FaIcon(FontAwesomeIcons.calendarAlt)
)
);
}
// Supplier part?
// TODO: Display supplier part info page?
/*
if (item.supplierPartId > 0) {
if (widget.item.link.isNotEmpty) {
tiles.add(
ListTile(
title: Text("${item.supplierName}"),
subtitle: Text("${item.supplierSKU}"),
leading: FaIcon(FontAwesomeIcons.industry),
trailing: InvenTreeAPI().getImage(item.supplierImage),
onTap: null,
)
);
}
*/
if (item.link.isNotEmpty) {
tiles.add(
ListTile(
title: Text("${item.link}"),
title: Text("${widget.item.link}"),
leading: FaIcon(FontAwesomeIcons.link, color: COLOR_CLICK),
onTap: () {
item.openLink();
widget.item.openLink();
},
)
);
}
if ((item.testResultCount > 0) || (part?.isTrackable ?? false)) {
if ((widget.item.testResultCount > 0) || (part?.isTrackable ?? false)) {
tiles.add(
ListTile(
title: Text(L10().testResults),
leading: FaIcon(FontAwesomeIcons.tasks, color: COLOR_CLICK),
trailing: Text("${item.testResultCount}"),
trailing: Text("${widget.item.testResultCount}"),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StockItemTestResultsWidget(item))
builder: (context) => StockItemTestResultsWidget(widget.item))
).then((ctx) {
refresh(context);
});
@ -657,29 +670,29 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
);
}
if (item.hasPurchasePrice) {
if (widget.item.hasPurchasePrice) {
tiles.add(
ListTile(
title: Text(L10().purchasePrice),
leading: FaIcon(FontAwesomeIcons.dollarSign),
trailing: Text(item.purchasePrice),
trailing: Text(widget.item.purchasePrice),
)
);
}
// TODO - Is this stock item linked to a PurchaseOrder?
if (stockShowHistory && item.trackingItemCount > 0) {
if (stockShowHistory && widget.item.trackingItemCount > 0) {
tiles.add(
ListTile(
title: Text(L10().history),
leading: FaIcon(FontAwesomeIcons.history, color: COLOR_CLICK),
trailing: Text("${item.trackingItemCount}"),
trailing: Text("${widget.item.trackingItemCount}"),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StockItemHistoryWidget(item))
builder: (context) => StockItemHistoryWidget(widget.item))
).then((ctx) {
refresh(context);
});
@ -696,7 +709,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => StockNotesWidget(item))
MaterialPageRoute(builder: (context) => StockNotesWidget(widget.item))
);
}
)
@ -713,7 +726,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
MaterialPageRoute(
builder: (context) => AttachmentWidget(
InvenTreeStockItemAttachment(),
item.pk,
widget.item.pk,
InvenTreeAPI().checkPermission("stock", "change"))
)
);
@ -748,13 +761,13 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}
// "Count" is not available for serialized stock
if (!item.isSerialized()) {
if (!widget.item.isSerialized()) {
tiles.add(
ListTile(
title: Text(L10().countStock),
leading: FaIcon(FontAwesomeIcons.checkCircle, color: COLOR_CLICK),
onTap: _countStockDialog,
trailing: Text(item.quantityString(includeUnits: true)),
trailing: Text(widget.item.quantityString(includeUnits: true)),
)
);
@ -794,7 +807,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => InvenTreeQRView(StockItemScanIntoLocationHandler(item)))
MaterialPageRoute(builder: (context) => InvenTreeQRView(StockItemScanIntoLocationHandler(widget.item)))
).then((ctx) {
refresh(context);
});
@ -802,8 +815,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
)
);
if (InvenTreeAPI().supportModernBarcodes || item.customBarcode.isEmpty) {
tiles.add(customBarcodeActionTile(context, this, item.customBarcode, "stockitem", item.pk));
if (InvenTreeAPI().supportModernBarcodes || widget.item.customBarcode.isEmpty) {
tiles.add(customBarcodeActionTile(context, this, widget.item.customBarcode, "stockitem", widget.item.pk));
} else {
// Note: Custom legacy barcodes (only for StockItem model) are handled differently
tiles.add(
@ -811,7 +824,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
title: Text(L10().barcodeUnassign),
leading: Icon(Icons.qr_code, color: COLOR_CLICK),
onTap: () async {
await item.update(values: {"uid": ""});
await widget.item.update(values: {"uid": ""});
refresh(context);
}
)