2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Create new stock item

This commit is contained in:
Oliver 2021-08-15 14:44:40 +10:00
parent a09d0b6887
commit 3fb6b38930
4 changed files with 78 additions and 2 deletions

View File

@ -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() {

View File

@ -108,6 +108,16 @@ class InvenTreeStockItem extends InvenTreeModel {
@override
String WEB_URL = "stock/item/";
@override
Map<String, dynamic> formFields() {
return {
"part": {},
"location": {},
"status": {},
"quantity": {},
};
}
@override
Map<String, String> defaultGetFilters() {

@ -1 +1 @@
Subproject commit 8f8a04c7bd8ff02f2dbfa75ef168ce812503a31e
Subproject commit f4f7b95c28f82bfd4e398ec5bb5e35823102323c

View File

@ -163,7 +163,31 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
Future<void> _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<Widget> 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) {