mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-29 14:06:47 +00:00
Catch POST response which does not return 201
This commit is contained in:
parent
16f4f7195c
commit
d53773d95c
@ -242,8 +242,14 @@ class InvenTreeModel {
|
|||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
.then((http.Response response) {
|
.then((http.Response response) {
|
||||||
|
// Server should return HTTP_201_CREATED
|
||||||
|
if (response.statusCode == 201) {
|
||||||
var decoded = json.decode(response.body);
|
var decoded = json.decode(response.body);
|
||||||
_model = createFromJson(decoded);
|
_model = createFromJson(decoded);
|
||||||
|
} else {
|
||||||
|
print("Error creating object: Status Code ${response.statusCode}");
|
||||||
|
print(response.body);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return _model;
|
return _model;
|
||||||
|
@ -88,7 +88,7 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
|
|
||||||
// Get all the test templates associated with this StockItem
|
// Get all the test templates associated with this StockItem
|
||||||
Future<void> getTestTemplates(BuildContext context, {bool showDialog=false}) async {
|
Future<void> getTestTemplates(BuildContext context, {bool showDialog=false}) async {
|
||||||
InvenTreePartTestTemplate().list(
|
await InvenTreePartTestTemplate().list(
|
||||||
context,
|
context,
|
||||||
filters: {
|
filters: {
|
||||||
"part": "${partId}",
|
"part": "${partId}",
|
||||||
@ -110,7 +110,8 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
int get testResultCount => testResults.length;
|
int get testResultCount => testResults.length;
|
||||||
|
|
||||||
Future<void> getTestResults(BuildContext context, {bool showDialog=false}) async {
|
Future<void> getTestResults(BuildContext context, {bool showDialog=false}) async {
|
||||||
InvenTreeStockItemTestResult().list(
|
|
||||||
|
await InvenTreeStockItemTestResult().list(
|
||||||
context,
|
context,
|
||||||
filters: {
|
filters: {
|
||||||
"stock_item": "${pk}",
|
"stock_item": "${pk}",
|
||||||
@ -144,7 +145,6 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
data["notes"] = notes;
|
data["notes"] = notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool _result = false;
|
bool _result = false;
|
||||||
|
|
||||||
await InvenTreeStockItemTestResult().create(context, data).then((InvenTreeModel model) {
|
await InvenTreeStockItemTestResult().create(context, data).then((InvenTreeModel model) {
|
||||||
|
@ -5,6 +5,8 @@ import 'package:InvenTree/api.dart';
|
|||||||
import 'package:InvenTree/widget/dialogs.dart';
|
import 'package:InvenTree/widget/dialogs.dart';
|
||||||
import 'package:InvenTree/widget/fields.dart';
|
import 'package:InvenTree/widget/fields.dart';
|
||||||
|
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:InvenTree/widget/refreshable_state.dart';
|
import 'package:InvenTree/widget/refreshable_state.dart';
|
||||||
@ -39,7 +41,25 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
|
|
||||||
_StockItemTestResultDisplayState(this.item);
|
_StockItemTestResultDisplayState(this.item);
|
||||||
|
|
||||||
void addTestResult({String name = '', bool nameIsEditable = true, bool result = false, String value = '', bool valueRequired = false, bool attachmentRequired = false}) {
|
void uploadTestResult(String name, bool result, String value, String notes) async {
|
||||||
|
|
||||||
|
item.uploadTestResult(
|
||||||
|
context,
|
||||||
|
name,
|
||||||
|
result,
|
||||||
|
value: value,
|
||||||
|
notes: notes,
|
||||||
|
).then((bool success) {
|
||||||
|
if (success) {
|
||||||
|
// TODO - Show a SnackBar here!
|
||||||
|
refresh();
|
||||||
|
} else {
|
||||||
|
showErrorDialog(context, "Error", "Could not upload test result to server");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void addTestResult({String name = '', bool nameIsEditable = true, bool result = false, String value = '', bool valueRequired = false, bool attachmentRequired = false}) async {
|
||||||
|
|
||||||
String _name;
|
String _name;
|
||||||
bool _result;
|
bool _result;
|
||||||
@ -59,16 +79,9 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
child: Text("Save"),
|
child: Text("Save"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_addResultKey.currentState.validate()) {
|
if (_addResultKey.currentState.validate()) {
|
||||||
|
|
||||||
_addResultKey.currentState.save();
|
_addResultKey.currentState.save();
|
||||||
|
Navigator.pop(context);
|
||||||
item.uploadTestResult(
|
uploadTestResult(_name, _result, _value, _notes);
|
||||||
context,
|
|
||||||
_name,
|
|
||||||
_result,
|
|
||||||
value: _value,
|
|
||||||
notes: _notes,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -92,7 +105,6 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
allowEmpty: true,
|
allowEmpty: true,
|
||||||
onSaved: (value) => _value = value,
|
onSaved: (value) => _value = value,
|
||||||
validator: (String value) {
|
validator: (String value) {
|
||||||
print("Value: " + value);
|
|
||||||
if (valueRequired && (value == null || value.isEmpty)) {
|
if (valueRequired && (value == null || value.isEmpty)) {
|
||||||
return "Value required for this test";
|
return "Value required for this test";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user