mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-30 14:36:47 +00:00
Scan items into location from location context
This commit is contained in:
parent
b7e9c06dfa
commit
24b7cfaede
174
lib/barcode.dart
174
lib/barcode.dart
@ -267,6 +267,116 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class StockItemScanIntoLocationHandler extends BarcodeHandler {
|
||||
/**
|
||||
* Barcode handler for scanning a provided StockItem into a scanned StockLocation
|
||||
*/
|
||||
|
||||
final InvenTreeStockItem item;
|
||||
|
||||
StockItemScanIntoLocationHandler(this.item);
|
||||
|
||||
@override
|
||||
String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanLocation;
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||
// If the barcode points to a 'stocklocation', great!
|
||||
if (data.containsKey('stocklocation')) {
|
||||
// Extract location information
|
||||
int location = data['stocklocation']['pk'] as int;
|
||||
|
||||
// Transfer stock to specified location
|
||||
final result = await item.transferStock(location);
|
||||
|
||||
if (result) {
|
||||
// Close the scanner
|
||||
_controller.dispose();
|
||||
Navigator.of(_context).pop();
|
||||
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).barcodeScanIntoLocationSuccess,
|
||||
success: true,
|
||||
);
|
||||
} else {
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).barcodeScanIntoLocationFailure,
|
||||
success: false
|
||||
);
|
||||
}
|
||||
} else {
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).invalidStockLocation,
|
||||
success: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class StockLocationScanInItemsHandler extends BarcodeHandler {
|
||||
/**
|
||||
* Barcode handler for scanning stock item(s) into the specified StockLocation
|
||||
*/
|
||||
|
||||
final InvenTreeStockLocation location;
|
||||
|
||||
StockLocationScanInItemsHandler(this.location);
|
||||
|
||||
@override
|
||||
String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanItem;
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||
|
||||
// Returned barcode must match a stock item
|
||||
if (data.containsKey('stockitem')) {
|
||||
|
||||
int item_id = data['stockitem']['pk'] as int;
|
||||
|
||||
final InvenTreeStockItem item = await InvenTreeStockItem().get(_context, item_id);
|
||||
|
||||
if (item == null) {
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).invalidStockItem,
|
||||
success: false,
|
||||
);
|
||||
} else if (item.locationId == location.pk) {
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).itemInLocation,
|
||||
success: true
|
||||
);
|
||||
}
|
||||
|
||||
else {
|
||||
final result = await item.transferStock(location.pk);
|
||||
|
||||
if (result) {
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).barcodeScanIntoLocationSuccess,
|
||||
success: true
|
||||
);
|
||||
} else {
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).barcodeScanIntoLocationFailure,
|
||||
success: false
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Does not match a valid stock item!
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).invalidStockItem,
|
||||
success: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class InvenTreeQRView extends StatefulWidget {
|
||||
|
||||
final BarcodeHandler _handler;
|
||||
@ -348,70 +458,6 @@ class _QRViewState extends State<InvenTreeQRView> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class StockItemScanIntoLocationHandler extends BarcodeHandler {
|
||||
/**
|
||||
* Barcode handler for scanning a provided StockItem into a scanned StockLocation
|
||||
*/
|
||||
|
||||
final InvenTreeStockItem item;
|
||||
|
||||
StockItemScanIntoLocationHandler(this.item);
|
||||
|
||||
@override
|
||||
String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanLocation;
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) {
|
||||
// If the barcode points to a 'stocklocation', great!
|
||||
if (data.containsKey('stocklocation')) {
|
||||
// Extract location information
|
||||
int location = data['stocklocation']['pk'] as int;
|
||||
|
||||
// Transfer stock to specified location
|
||||
item.transferStock(location).then((response) {
|
||||
print("Response: ${response.statusCode}");
|
||||
|
||||
// Close the scanner
|
||||
_controller.dispose();
|
||||
Navigator.of(_context).pop();
|
||||
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).barcodeScanIntoLocationSuccess,
|
||||
success: true,
|
||||
);
|
||||
|
||||
});
|
||||
} else {
|
||||
showSnackIcon(
|
||||
I18N.of(OneContext().context).invalidStockLocation,
|
||||
success: false,
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class StockLocationScanInItemsHandler extends BarcodeHandler {
|
||||
/**
|
||||
* Barcode handler for scanning stock item(s) into the specified StockLocation
|
||||
*/
|
||||
|
||||
final InvenTreeStockLocation location;
|
||||
|
||||
StockLocationScanInItemsHandler(this.location);
|
||||
|
||||
@override
|
||||
String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanItem;
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) {
|
||||
print("TODO, YO!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> scanQrCode(BuildContext context) async {
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeQRView(BarcodeScanHandler())));
|
||||
|
@ -486,7 +486,7 @@ class InvenTreeStockItem extends InvenTreeModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<http.Response> transferStock(int location, {double quantity, String notes}) async {
|
||||
Future<bool> transferStock(int location, {double quantity, String notes}) async {
|
||||
if (quantity == null) {} else
|
||||
if ((quantity < 0) || (quantity > this.quantity)) {
|
||||
quantity = this.quantity;
|
||||
@ -504,7 +504,9 @@ class InvenTreeStockItem extends InvenTreeModel {
|
||||
data["item"]["quantity"] = "${quantity}";
|
||||
}
|
||||
|
||||
return api.post("/stock/transfer/", body: data);
|
||||
final response = await api.post("/stock/transfer/", body: data);
|
||||
|
||||
return (response.statusCode == 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
2
lib/l10n
2
lib/l10n
@ -1 +1 @@
|
||||
Subproject commit 0e412995061a5b01530d0929f80e06c29ff639f8
|
||||
Subproject commit bc85d5b16cd74623ce42bd82b3ac30b9be1da6c6
|
@ -1,4 +1,5 @@
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:InvenTree/barcode.dart';
|
||||
import 'package:InvenTree/inventree/stock.dart';
|
||||
import 'package:InvenTree/preferences.dart';
|
||||
import 'package:InvenTree/widget/progress.dart';
|
||||
@ -224,12 +225,10 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||
label: I18N.of(context).stock,
|
||||
),
|
||||
// TODO - Add in actions when they are written...
|
||||
/*
|
||||
BottomNavigationBarItem(
|
||||
icon: FaIcon(FontAwesomeIcons.wrench),
|
||||
label: I18N.of(context).actions,
|
||||
)
|
||||
*/
|
||||
]
|
||||
);
|
||||
}
|
||||
@ -324,14 +323,23 @@ List<Widget> detailTiles() {
|
||||
// Scan items into location
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text("Scan in Stock Item"),
|
||||
title: Text(I18N.of(context).barcodeScanInItems),
|
||||
leading: FaIcon(FontAwesomeIcons.exchangeAlt),
|
||||
trailing: FaIcon(FontAwesomeIcons.qrcode),
|
||||
onTap: null,
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => InvenTreeQRView(StockLocationScanInItemsHandler(location)))
|
||||
).then((context) {
|
||||
refresh();
|
||||
});
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
// Move location into another location
|
||||
// TODO: Implement this!
|
||||
/*
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text("Move Stock Location"),
|
||||
@ -339,6 +347,7 @@ List<Widget> detailTiles() {
|
||||
trailing: FaIcon(FontAwesomeIcons.qrcode),
|
||||
)
|
||||
);
|
||||
*/
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user