mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-17 12:45:26 +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:
@ -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
|
||||
|
Reference in New Issue
Block a user