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

Bug fix and refactoring

- Display difference between "in stock" and "unallocated stock"
- Refactor to use single function in detail and list widgets
This commit is contained in:
Oliver Walters 2022-04-18 21:49:10 +10:00
parent 8d255885cf
commit 84edaef10a
3 changed files with 31 additions and 16 deletions

View File

@ -269,17 +269,18 @@ class InvenTreePart extends InvenTreeModel {
}
// Get the 'available stock' for this Part
double get availableStock {
double get unallocatedStock {
// Note that the 'available_stock' was not added until API v35
if (jsondata.containsKey("available_stock")) {
return double.tryParse(jsondata["available_stock"].toString()) ?? 0;
if (jsondata.containsKey("unallocated_stock")) {
return double.tryParse(jsondata["unallocated_stock"].toString()) ?? 0;
} else {
return inStock;
}
}
String get availableStockString {
String q = simpleNumberString(availableStock);
String get unallocatedStockString {
String q = simpleNumberString(unallocatedStock);
if (units.isNotEmpty) {
q += " ${units}";
@ -288,6 +289,20 @@ class InvenTreePart extends InvenTreeModel {
return q;
}
String stockString({bool includeUnits = true}) {
String q = unallocatedStockString;
if (unallocatedStock != inStock) {
q += " / ${inStockString}";
}
if (includeUnits && units.isNotEmpty) {
q += " ${units}";
}
return q;
}
String get units => (jsondata["units"] ?? "") as String;
// Get the number of units being build for this Part

View File

@ -209,19 +209,19 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
subtitle: Text(L10().partCategoryTopLevel),
leading: FaIcon(FontAwesomeIcons.sitemap, color: COLOR_CLICK),
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)));
Navigator.push(context, MaterialPageRoute(
builder: (context) => CategoryDisplayWidget(null)));
},
)
);
}
// Stock information
tiles.add(
ListTile(
title: Text(L10().availableStock),
subtitle: Text(L10().stockDetails),
leading: FaIcon(FontAwesomeIcons.boxes, color: COLOR_CLICK),
trailing: Text(part.availableStockString),
trailing: Text(part.stockString()),
onTap: () {
setState(() {
tabIndex = 1;

View File

@ -87,7 +87,7 @@ class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> {
return ListTile(
title: Text(part.fullname),
subtitle: Text(part.description),
trailing: Text(part.availableStockString),
trailing: Text(part.stockString()),
leading: InvenTreeAPI().getImage(
part.thumbnail,
width: 40,