Repository navigation
Create simple endpoint for barcode decode - #722
Conversation
- Registers some very simple barcode plugins
- Simplify InvenTree barcode format - Create base-clas for plugin
- To be used for barcode asociation and lookup
- DigiKey barcode is NOT json formatted, for example...
|
@maholli there is now an endpoint /api/barcode/ to throw some data at. It expects a simple data format: Currently it works to decode the native InvenTree style barcodes, with a skeleton wrapper for DigiKey codes. The StockItem model now also has a "UID" field which can be mapped to a barcode hash |
- Plugin for running a custom action
@SchrodingersGat I think there's some confusion of terminology (at least in my head). I've been calling:
Since you mentioned you have zxing working for the mobile app, I've been under the assumption you have a method/plan for acquiring the barcode data. So is the endpoint /api/barcode/ expecting barcode data or part data? |
|
The endpoint expects |
|
The server then tries to find a plugin that knows how to decode the particular barcode data, and then will return a response from that plugin. The native "InvenTree style" barcode plugin simply performs a database lookup on the provided data which might be like: |
|
So a digikey barcode plugin logic would be, (roughly):
|
|
In the case of the InvenTree barcode shown above, the server would respond with something like: (Note this is actually a scan result for a different stockitem, but you get the idea) This example data is "real" - i.e. scanned via the InvenTree app, sent to the server, and then the app will redirect to the detail view for the given stockitem. |
- This is the code that the Supplier uses for the particuarl sales order
|
Looking great @SchrodingersGat! 👍 Did you get a chance to run one of your component-bag barcodes through getparts()? I can easily add InvenTree QR codes as an option, but I'll need your feedback on usability |
|
Not yet, although I would like to soon. The inventree-style QR codes do not need any API lookup - they map directly to items in the database so all that info is directly available. Your API code would be useful when the parts are first scanned into the system - grab any data from the API and match it against the database. I need to have a think about how best to present the data to the user, though. And now that the barcode API is working, I'd like to start thinking about supporting barcode scanning via the web interface - e.g. a webcam or connected USB camera |
|
@maholli here's where I see this progressing from here: There's currently a skeleton for a digikey barcode plugin. You have already written code to recognize a digikey barcode and then perform API lookup. This code should be integrated into the barcode plugin: Recognize BarcodeFirst step is to parse the barcode data and say "Yes, this looks like a digikey barcode! Simply extend the class skeleton which is provided at:
Request API dataSend the barcode data to the digikey API and then return a JSON object. Here you will need to supply an API key. The InvenTree database already supports arbitrary key:value pairs (see So you could call something like: from common.models import InvenTreeSetting
# See if there is a digikey api key available
# The call will return None if the key does not exist.
api_key = InvenTreeSetting.get_setting('digikey-api-key')Then the API key can be added to the database: Work out what to do with the returned dataIf you are willing to work on the two above points, then once we have data coming back from the digikey API is when things get really interesting! Let me know if you're able to look at these points. I'm happy to provide pointers where you need them! |
|
@SchrodingersGat I'm happy to put together the plugin and demo the functionality, so I'll take a crack at this weekend. That being said, I still think the supplier-specific plugin approach is setting us up for inefficiency. Would you be opposed to something like an |
|
I would strongly prefer the functionality to be split into separate plugins, the point of the plugin architecture is to separate the functionality out so code for one supplied does not "infect" the code for another. I can imagine the code for the digikey api growing and becoming pretty complex. Then as more manufacturers are added, the single plugin becomes very bloated. With regards to inefficiency, code which is common between supplier plugins can be refactored to the parent BarcodePlugin class, there should be minimum code duplication. |
|
If I understand correctly, the /api/barcode/ endpoint looks for either a raw string OR a dict , and then attempts to match it to the appropriate decoding plugin by asking each available plugin to validate it? So, could I pass in a list of barcode objects captured from a single bag? I see that the Inventree barcode plugin looks first at the data type to see if it's a dict or a string - is there data validation that would reject a list, or some other reason I couldn't pass a list straight from pyzbar?? Extending maholli's webcam_example.py, I am decoding all the barcodes from a bag in one capture. I have devised a strategy for uniquely identifying the vendor who produced the bag based on the pattern of barcode locations and types, so that I can then map the decoded barcodes to the appropriate fields (MPN, vendor, SKU, quantity, etc). We can create a unique hash from the combination of these fields, too. My intended strategy was to capture the array of barcodes, identify the vendor, and then call the appropriate mapping function to assign content to fields - all outside of InvenTree. Seems like the main question (to me) is whether I can pass a list in. If so, I think the rest fits well into the architecture you've developed. Thoughts? |
|
That's a very interesting approach! There's no reason that you can't make a Barcode plugin which accepts multiple barcodes at once. The barcode data could be a list of barcode data for sure. The particular plugin just needs to be able to interpret the data. Please keep me posted if you actually develop this! |





API endpoint for checking barcode data
Fixes #713
This PR provides a "plugin" architecture (finally!) - the first implemented plugin is a barcode interface.
Third-party barcode plugins can then be implemented wholly separate from the database code!