2
0
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:
Oliver
2022-12-05 23:39:40 +11:00
committed by GitHub
parent efb6fc353e
commit 730521fd00
11 changed files with 162 additions and 134 deletions

View File

@ -453,6 +453,12 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
)
);
}
if (InvenTreeAPI().supportModernBarcodes) {
tiles.add(
customBarcodeActionTile(context, location!.customBarcode, "stocklocation", location!.pk)
);
}
}
}

View File

@ -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;
}

View File

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