[FR] Create/update part from barcode scan
Please verify that this feature request has NOT been suggested before.
- [x] I checked and didn't find a similar feature request
Problem statement
Right now when I scan a Digikey barcode that isn't in my Inventree instance I just get a no match error.
Suggested solution
I have a large box of untracked components leftover from various projects. It would be nice to be able to scan them and then use the extracted component details to partially fill out the new part form.
Also, it would be nice to have the option of adding/merging the scanned data into an existing part. For example, if you scanned a SMT resistor instead of creating a new part you could select an existing matching part from the database and then relevant data such as the new supplier info would be added.
Describe alternatives you've considered
The first case of just creating a new part could probably be done as a separate app/script and then access Inventree through the API but that seems hacky.
Examples of other systems
No response
Do you want to develop this?
- [x] I want to develop this.
We already have digikey matching; please provide barcodes (or better just the data string) that do not work
As far as I can tell the matching only works if the part already exists in the database?
I did some digging and it seems like the barcode decoding endpoint only returns the barcode data if it matches something already in the database:
{
"supplierpart": {
"pk": 1,
"api_url": "/api/company/part/1/",
"instance": {
"available": 0.0,
...
}
},
"company": {
"pk": 1
},
"success": "Match found for barcode data",
"plugin": "DigiKeyBarcodePlugin",
"barcode_data": "[)>\u001e06\u001dP609-4310-1-ND\u001d1PSFV14R-2STE1HLF\u001dK\u001d1K65956998\u001d10K76072196\u001d11K1\u001d4LMY\u001dQ6\u001d11ZPICK\u001d12Z2626761\u001d13Z793697\u001d20Z000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"barcode_hash": "251795f4ffb8f29f9ca96fd9f2d6f611"
}
If i delete the part I instead get:
{
"plugin": "None",
"barcode_data": "[)>\u001e06\u001dP609-4310-1-ND\u001d1PSFV14R-2STE1HLF\u001dK\u001d1K65956998\u001d10K76072196\u001d11K1\u001d4LMY\u001dQ6\u001d11ZPICK\u001d12Z2626761\u001d13Z793697\u001d20Z000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"barcode_hash": "251795f4ffb8f29f9ca96fd9f2d6f611",
"error": "No match found for barcode data"
}
For starters it would be good if the API returns the decoded data regardless of whether or not a match is found.
Looks like the main logic for this is in SupplierBarcodeMixin.scan, which currently just returns None if no match is found.
https://github.com/inventree/InvenTree/blob/6581af716534cb6798a60106b875ce8a336e8058/src/backend/InvenTree/plugin/base/barcodes/mixins.py#L298-L304
It might be better if no match is found that we fall back to returning data for a scan that at least decoded correctly, maybe with a 'error' key set to something like "No matching item found"
With the data always returned, the frontend can then display the decoded output, and possibly show a button to use that data to create a new part. Some logic would be needed to determine if the returned data is in fact part data, but that can probably be determined from the plugin type? (i.e. if it's a QR code for a non-existent stock location or something no button would show)
With the data always returned, the frontend can then display the decoded output, and possibly show a button to use that data to create a new part.
This would require some complex logic to get right, and make it generic / useful...
The existing barcode plugin structure already would allow the workflow (minus the frontend / UI integration). You could have a custom plugin which:
- determines that the scanned data does not match an existing part
- create a new part with the provided data / API calls
- return the newly created part
Maybe I just haven't looked enough into it, but I thought barcode plugins like the digikey one are just returning decoded data for the parent class implementation of scan to then find a match.
If I were to make a new barcode plugin it doesn't seem like there would be a nice way to pass the decoded data from other plugins without just reimplementing decoders for all the suppliers?
@Gigahawk thinking about this a little further, I think that if you wanted to do this it would make sense to provide a custom plugin that generates the front-end user interface, as well as a custom API endpoint for handling the scanned data / processing the barcode results.
This way the user can specify the part category, some default values, etc.
It could be a very useful tool!
I was just looking for this exact feature for this exact use case. I am needing to track and add digikey components at small scale (around a hundred components). When adding new components, it would be great to scan the 2d code and auto populate the forum to add a new stock item. I am interested in both DigiKey and LCSC at the moment.