mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-13 10:45:29 +00:00
New barcode actions (#218)
* Bump release notes * Adds method for linking custom barcodes * Custom getter method for determining if an item has barcode data * Add method to check if the API supports "modern" barcodes * Refactor custom barcode implementation for StockItem - Needs testing * Unit testing for linking and unlinking barcodes * Fixes * Refactor code for "custom barcode action" tile * Add custom barcode action to StockLocation * Add extra debug to debug the debugging * Unit test fix * Change scope I guess? * remove handler test
This commit is contained in:
@ -453,6 +453,12 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (InvenTreeAPI().supportModernBarcodes) {
|
||||
tiles.add(
|
||||
customBarcodeActionTile(context, location!.customBarcode, "stocklocation", location!.pk)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/barcode.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/helpers.dart";
|
||||
|
||||
@ -695,35 +696,11 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
)
|
||||
);
|
||||
|
||||
// TODO - Add this action back in once implemented
|
||||
/*
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().barcodeScanItem),
|
||||
leading: FaIcon(FontAwesomeIcons.box),
|
||||
trailing: Icon(Icons.qr_code),
|
||||
onTap: () {
|
||||
// TODO
|
||||
},
|
||||
),
|
||||
);
|
||||
*/
|
||||
|
||||
/*
|
||||
// TODO: Implement part deletion
|
||||
if (!part.isActive && InvenTreeAPI().checkPermission("part", "delete")) {
|
||||
if (InvenTreeAPI().supportModernBarcodes) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().deletePart),
|
||||
subtitle: Text(L10().deletePartDetail),
|
||||
leading: FaIcon(FontAwesomeIcons.trashAlt, color: COLOR_DANGER),
|
||||
onTap: () {
|
||||
// TODO
|
||||
},
|
||||
)
|
||||
customBarcodeActionTile(context, part.customBarcode, "part", part.pk)
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
@ -416,48 +416,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Unassign (remove) a barcode from a StockItem.
|
||||
*
|
||||
* Note that for API version < 76 this action is performed on the StockItem endpoint.
|
||||
* For API version 76 or above, this uses the barcode "unlink" endpoint
|
||||
*/
|
||||
Future<void> _unassignBarcode(BuildContext context) async {
|
||||
|
||||
if (InvenTreeAPI().apiVersion < 76) {
|
||||
final response = await item.update(values: {"uid": ""});
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
case 201:
|
||||
showSnackIcon(
|
||||
L10().stockItemUpdateSuccess,
|
||||
success: true
|
||||
);
|
||||
break;
|
||||
default:
|
||||
showSnackIcon(
|
||||
L10().stockItemUpdateFailure,
|
||||
success: false,
|
||||
);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
final bool result = await InvenTreeAPI().unlinkBarcode({
|
||||
"stockitem": item.pk,
|
||||
});
|
||||
|
||||
showSnackIcon(
|
||||
result ? L10().stockItemUpdateSuccess : L10().stockItemUpdateFailure,
|
||||
success: result,
|
||||
);
|
||||
}
|
||||
|
||||
refresh(context);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Launches an API Form to transfer this stock item to a new location
|
||||
*/
|
||||
@ -844,59 +802,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
)
|
||||
);
|
||||
|
||||
// Add or remove custom barcode
|
||||
if (item.uid.isEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().barcodeAssign),
|
||||
subtitle: Text(L10().barcodeAssignDetail),
|
||||
leading: Icon(Icons.qr_code),
|
||||
trailing: Icon(Icons.qr_code_scanner),
|
||||
onTap: () {
|
||||
|
||||
var handler = UniqueBarcodeHandler((String hash) {
|
||||
item.update(
|
||||
values: {
|
||||
"uid": hash,
|
||||
}
|
||||
).then((response) {
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
case 201:
|
||||
barcodeSuccessTone();
|
||||
|
||||
showSnackIcon(
|
||||
L10().barcodeAssigned,
|
||||
success: true,
|
||||
icon: Icons.qr_code,
|
||||
);
|
||||
|
||||
refresh(context);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => InvenTreeQRView(handler))
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
} else {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().barcodeUnassign),
|
||||
leading: Icon(Icons.qr_code, color: COLOR_CLICK),
|
||||
onTap: () {
|
||||
_unassignBarcode(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
if (InvenTreeAPI().supportModernBarcodes) {
|
||||
tiles.add(customBarcodeActionTile(context, item.customBarcode, "stockitem", item.pk));
|
||||
}
|
||||
|
||||
// Print label (if label printing plugins exist)
|
||||
|
Reference in New Issue
Block a user