2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-05-02 23:38:54 +00:00

Use 'available_stock' when available (new API)

This commit is contained in:
Oliver Walters 2022-04-18 21:39:09 +10:00
parent 2c660e3961
commit 046af50146
2 changed files with 65 additions and 49 deletions

View File

@ -1,6 +1,7 @@
import "dart:io";
import "package:inventree/api.dart";
import "package:inventree/helpers.dart";
import "package:inventree/inventree/stock.dart";
import "package:inventree/inventree/company.dart";
import "package:flutter/material.dart";
@ -250,11 +251,7 @@ class InvenTreePart extends InvenTreeModel {
String get onOrderString {
if (onOrder == onOrder.toInt()) {
return onOrder.toInt().toString();
} else {
return onOrder.toString();
}
return simpleNumberString(onOrder);
}
// Get the stock count for this Part
@ -262,12 +259,28 @@ class InvenTreePart extends InvenTreeModel {
String get inStockString {
String q = inStock.toString();
String q = simpleNumberString(inStock);
if (inStock == inStock.toInt()) {
q = inStock.toInt().toString();
if (units.isNotEmpty) {
q += " ${units}";
}
return q;
}
// Get the 'available stock' for this Part
double get availableStock {
// Note that the 'available_stock' was not added until API v35
if (jsondata.containsKey("available_stock")) {
return double.tryParse(jsondata["available_stock"].toString()) ?? 0;
} else {
return inStock;
}
}
String get availableStockString {
String q = simpleNumberString(availableStock);
if (units.isNotEmpty) {
q += " ${units}";
}

View File

@ -218,10 +218,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
// Stock information
tiles.add(
ListTile(
title: Text(L10().stock),
title: Text(L10().availableStock),
subtitle: Text(L10().stockDetails),
leading: FaIcon(FontAwesomeIcons.boxes, color: COLOR_CLICK),
trailing: Text("${part.inStockString}"),
trailing: Text(part.availableStockString),
onTap: () {
setState(() {
tabIndex = 1;
@ -230,48 +230,9 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
),
);
// Keywords?
if (part.keywords.isNotEmpty) {
tiles.add(
ListTile(
title: Text("${part.keywords}"),
leading: FaIcon(FontAwesomeIcons.key),
)
);
}
// External link?
if (part.link.isNotEmpty) {
tiles.add(
ListTile(
title: Text("${part.link}"),
leading: FaIcon(FontAwesomeIcons.link, color: COLOR_CLICK),
onTap: () {
part.openLink();
},
)
);
}
// Tiles for "purchaseable" parts
if (part.isPurchaseable) {
tiles.add(
ListTile(
title: Text(L10().suppliers),
leading: FaIcon(FontAwesomeIcons.industry),
trailing: Text("${part.supplierCount}"),
/* TODO:
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PartSupplierWidget(part))
);
},
*/
)
);
// On order
tiles.add(
ListTile(
@ -317,6 +278,29 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
}
}
// Keywords?
if (part.keywords.isNotEmpty) {
tiles.add(
ListTile(
title: Text("${part.keywords}"),
leading: FaIcon(FontAwesomeIcons.key),
)
);
}
// External link?
if (part.link.isNotEmpty) {
tiles.add(
ListTile(
title: Text("${part.link}"),
leading: FaIcon(FontAwesomeIcons.link, color: COLOR_CLICK),
onTap: () {
part.openLink();
},
)
);
}
// Tiles for "component" part
if (part.isComponent && part.usedInCount > 0) {
@ -333,6 +317,25 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
);
}
if (part.isPurchaseable) {
tiles.add(
ListTile(
title: Text(L10().suppliers),
leading: FaIcon(FontAwesomeIcons.industry),
trailing: Text("${part.supplierCount}"),
/* TODO:
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PartSupplierWidget(part))
);
},
*/
)
);
}
// TODO - Add request tests?
/*
if (part.isTrackable) {