diff --git a/lib/api_form.dart b/lib/api_form.dart index 49e6bcd4..624c6e7d 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -154,6 +154,9 @@ class APIFormField { return _constructBoolean(); case "related field": return _constructRelatedField(); + case "float": + case "decimal": + return _constructFloatField(); case "choice": return _constructChoiceField(); default: @@ -203,6 +206,34 @@ class APIFormField { ); } + // Construct a floating point numerical input field + Widget _constructFloatField() { + + return TextFormField( + decoration: InputDecoration( + labelText: required ? label + "*" : label, + labelStyle: _labelStyle(), + helperText: helpText, + helperStyle: _helperStyle(), + hintText: placeholderText, + ), + initialValue: (value ?? 0).toString(), + keyboardType: TextInputType.numberWithOptions(signed: true, decimal: true), + validator: (value) { + + double? quantity = double.tryParse(value.toString()) ?? null; + + if (quantity == null) { + return L10().numberInvalid; + } + }, + onSaved: (val) { + data["value"] = val; + }, + ); + + } + // Construct an input for a related field Widget _constructRelatedField() { diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 6072b72b..f1dd773d 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -108,6 +108,16 @@ class InvenTreeStockItem extends InvenTreeModel { @override String WEB_URL = "stock/item/"; + @override + Map formFields() { + return { + "part": {}, + "location": {}, + "status": {}, + "quantity": {}, + }; + } + @override Map defaultGetFilters() { diff --git a/lib/l10n b/lib/l10n index 8f8a04c7..f4f7b95c 160000 --- a/lib/l10n +++ b/lib/l10n @@ -1 +1 @@ -Subproject commit 8f8a04c7bd8ff02f2dbfa75ef168ce812503a31e +Subproject commit f4f7b95c28f82bfd4e398ec5bb5e35823102323c diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index c35d408d..c26d8999 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -163,7 +163,31 @@ class _LocationDisplayState extends RefreshableState { Future _newStockItem(BuildContext context) async { - // TODO + int pk = location?.pk ?? -1; + + if (pk <= 0) { + return; + } + + InvenTreeStockItem().createForm( + context, + L10().stockItemCreate, + data: { + "location": pk, + }, + onSuccess: (data) async { + if (data.containsKey("pk")) { + var item = InvenTreeStockItem.fromJson(data); + + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => StockDetailWidget(item) + ) + ); + } + } + ); } @@ -320,6 +344,17 @@ List detailTiles() { ) ); + tiles.add( + ListTile( + title: Text(L10().stockItemCreate), + subtitle: Text(L10().stockItemCreateDetail), + leading: FaIcon(FontAwesomeIcons.boxes, color: COLOR_CLICK), + onTap: () async { + _newStockItem(context); + }, + ) + ); + } if (location != null) {