2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Further barcode work

- Simplify InvenTree barcode format
- Create base-clas for plugin
This commit is contained in:
Oliver Walters
2020-04-14 21:30:43 +10:00
parent 70589b06e1
commit 4a615e05ae
9 changed files with 127 additions and 49 deletions

View File

@ -1,19 +1,25 @@
# -*- coding: utf-8 -*-
import plugins.plugin as plugin
class BarcodePlugin:
class BarcodePlugin(plugin.InvenTreePlugin):
"""
The BarcodePlugin class is the base class for any barcode plugin.
"""
# Override this for each actual plugin
PLUGIN_NAME = ''
def validate_barcode(self, barcode_data):
"""
Default implementation returns False
"""
return False
def decode_barcode(self, barcode_data):
"""
Decode the barcode, and craft a response
"""
return None
def __init__(self):
pass
plugin.InvenTreePlugin.__init__(self)

View File

@ -8,7 +8,24 @@ class InvenTreeBarcodePlugin(barcode.BarcodePlugin):
PLUGIN_NAME = "InvenTreeBarcodePlugin"
def validate_barcode(self, barcode_data):
"""
An "InvenTree" barcode must include the following tags:
print("testing")
{
'tool': 'InvenTree',
'version': <anything>
}
"""
for key in ['tool', 'version']:
if key not in barcode_data.keys():
return False
if not barcode_data['tool'] == 'InvenTree':
return False
return True
def decode_barcode(self, barcode_data):
pass

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
class InvenTreePlugin():
"""
Base class for a Barcode plugin
"""
# Override the plugin name for each concrete plugin instance
PLUGIN_NAME = ''
def get_name(self):
return self.PLUGIN_NAME
def __init__(self):
pass

View File

@ -52,4 +52,12 @@ def load_barcode_plugins():
Return a list of all registered barcode plugins
"""
return get_plugins(barcode, BarcodePlugin)
plugins = get_plugins(barcode, BarcodePlugin)
if len(plugins) > 0:
print("Discovered {n} barcode plugins:".format(n=len(plugins)))
for bp in plugins:
print(" - {bp}".format(bp=bp.PLUGIN_NAME))
return plugins