mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-03 07:48:53 +00:00
Use 'available_stock' when available (new API)
This commit is contained in:
parent
2c660e3961
commit
046af50146
@ -1,6 +1,7 @@
|
|||||||
import "dart:io";
|
import "dart:io";
|
||||||
|
|
||||||
import "package:inventree/api.dart";
|
import "package:inventree/api.dart";
|
||||||
|
import "package:inventree/helpers.dart";
|
||||||
import "package:inventree/inventree/stock.dart";
|
import "package:inventree/inventree/stock.dart";
|
||||||
import "package:inventree/inventree/company.dart";
|
import "package:inventree/inventree/company.dart";
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
@ -250,11 +251,7 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
String get onOrderString {
|
String get onOrderString {
|
||||||
|
|
||||||
if (onOrder == onOrder.toInt()) {
|
return simpleNumberString(onOrder);
|
||||||
return onOrder.toInt().toString();
|
|
||||||
} else {
|
|
||||||
return onOrder.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the stock count for this Part
|
// Get the stock count for this Part
|
||||||
@ -262,12 +259,28 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
String get inStockString {
|
String get inStockString {
|
||||||
|
|
||||||
String q = inStock.toString();
|
String q = simpleNumberString(inStock);
|
||||||
|
|
||||||
if (inStock == inStock.toInt()) {
|
if (units.isNotEmpty) {
|
||||||
q = inStock.toInt().toString();
|
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) {
|
if (units.isNotEmpty) {
|
||||||
q += " ${units}";
|
q += " ${units}";
|
||||||
}
|
}
|
||||||
|
@ -218,10 +218,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
// Stock information
|
// Stock information
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().stock),
|
title: Text(L10().availableStock),
|
||||||
subtitle: Text(L10().stockDetails),
|
subtitle: Text(L10().stockDetails),
|
||||||
leading: FaIcon(FontAwesomeIcons.boxes, color: COLOR_CLICK),
|
leading: FaIcon(FontAwesomeIcons.boxes, color: COLOR_CLICK),
|
||||||
trailing: Text("${part.inStockString}"),
|
trailing: Text(part.availableStockString),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
tabIndex = 1;
|
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
|
// Tiles for "purchaseable" parts
|
||||||
if (part.isPurchaseable) {
|
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
|
// On order
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
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
|
// Tiles for "component" part
|
||||||
if (part.isComponent && part.usedInCount > 0) {
|
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?
|
// TODO - Add request tests?
|
||||||
/*
|
/*
|
||||||
if (part.isTrackable) {
|
if (part.isTrackable) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user