2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Update stock display to indicate allocations

This commit is contained in:
Oliver Walters 2022-07-05 18:38:28 +10:00
parent 62df40f4b3
commit 591c6a5592
3 changed files with 20 additions and 4 deletions

View File

@ -451,7 +451,14 @@ class InvenTreeStockItem extends InvenTreeModel {
String quantityString({bool includeUnits = false}){
String q = simpleNumberString(quantity);
String q = "";
if (allocated > 0) {
q += simpleNumberString(available);
q += " / ";
}
q += simpleNumberString(quantity);
if (includeUnits && units.isNotEmpty) {
q += " ${units}";
@ -460,6 +467,10 @@ class InvenTreeStockItem extends InvenTreeModel {
return q;
}
double get allocated => double.tryParse(jsondata["allocated"].toString()) ?? 0;
double get available => quantity - allocated;
int get locationId => (jsondata["location"] ?? -1) as int;
bool isSerialized() => serialNumber.isNotEmpty && quantity.toInt() == 1;
@ -467,10 +478,12 @@ class InvenTreeStockItem extends InvenTreeModel {
String serialOrQuantityDisplay() {
if (isSerialized()) {
return "SN ${serialNumber}";
}
} else if (allocated > 0) {
return "${available} / ${quantity}";
} else {
return simpleNumberString(quantity);
}
}
String get locationName {
String loc = "";

View File

@ -655,6 +655,9 @@
"description": "Quantity"
},
"quantityAvailable": "Quantity Available",
"@quantityAvailable": {},
"quantityEmpty": "Quantity is empty",
"@quantityEmpty": {},

View File

@ -513,7 +513,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
} else {
tiles.add(
ListTile(
title: Text(L10().quantity),
title: item.allocated > 0 ? Text(L10().quantityAvailable) : Text(L10().quantity),
leading: FaIcon(FontAwesomeIcons.cubes),
trailing: Text("${item.quantityString()}"),
)