Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanning a stock item into a location results in both success and failure feedback to the user #520

Open
awnz opened this issue Aug 16, 2024 · 2 comments

Comments

@awnz
Copy link
Contributor

awnz commented Aug 16, 2024

Hi all,

Awesome application! I've just deployed InvenTree to our little family business which was previously losing things regularly.

I'm encountering one issue with the InvenTree mobile app where the following happens when trying to scan a stock item into a location:

  1. Open InvenTree app (Android)
  2. Tap "Scan" icon, then scan a location QR code
  3. Tap "Scan Stock Item" and scan a stockitem
  4. The app reports "Scanned into location" with a barcode success beep
  5. The app then immediately also shows "Invalid Stock Item" with a barcode failure beep, misleading the user into thinking there's a problem

(The item is successfully scanned into the location, verified via the InvenTree web UI, so the error message is false).

This is my first dig into the source which I'm not familiar with, but I think the problem is in lib/barcode/stock.dart line 97, where the return statement shouldn't be inside that if block - I've added comments below:

class BarcodeScanStockItemHandler extends BarcodeHandler {

  @override
  String getOverlayText(BuildContext context) => L10().barcodeScanItem;

  @override
  Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
    // We expect that the barcode points to a 'stockitem'
    if (data.containsKey("stockitem")) {
      int _item = (data["stockitem"]["pk"] ?? -1) as int;

      // A valid stock location!
      if (_item > 0) {

        barcodeSuccessTone();

        bool result = await onItemScanned(_item);

        if (result && OneContext.hasContext) {
          OneContext().pop();
          return; // I think this...
        }
        // ...should be here?
      }
    }

    // If we get to this point, something went wrong during the scan process
    barcodeFailureTone();

    showSnackIcon(
      L10().invalidStockItem,
      success: false,
    );
  }

  // Callback function which runs when a valid StockItem is scanned
  Future<bool> onItemScanned(int itemId) async {
    // Re-implement this for particular subclass
    return false;
  }
}

(edit: fixed indentation)

Changing the above so that the return line is moved to where I commented "should be here?" looks to resolve the issue for me. I've tested both expected success (scan a stock item into a location - now doesn't produce the false error) and expected failure (try to scan a random grocery item that InvenTree doesn't know about into a location, correctly returns "No match found for barcode data" as expected).

Am I on the right track? If yes, let me know and I'll submit a PR.

@SchrodingersGat
Copy link
Member

@awnz looks like you're on the right track! Please submit a PR and I'll be happy to review :)

@awnz
Copy link
Contributor Author

awnz commented Aug 17, 2024

Thanks - created PR #521

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants