mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Consolidate InvenTree barcode plugins into single plugin class
This commit is contained in:
parent
53007dc416
commit
eee1464241
@ -11,8 +11,8 @@ from rest_framework.views import APIView
|
|||||||
|
|
||||||
from InvenTree.helpers import hash_barcode
|
from InvenTree.helpers import hash_barcode
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
from plugin.builtin.barcodes.inventree_barcode import (
|
from plugin.builtin.barcodes.inventree_barcode import \
|
||||||
InvenTreeExternalBarcodePlugin, InvenTreeInternalBarcodePlugin)
|
InvenTreeInternalBarcodePlugin
|
||||||
from users.models import RuleSet
|
from users.models import RuleSet
|
||||||
|
|
||||||
|
|
||||||
@ -56,7 +56,6 @@ class BarcodeScan(APIView):
|
|||||||
# Ensure that the default barcode handlers are run first
|
# Ensure that the default barcode handlers are run first
|
||||||
plugins = [
|
plugins = [
|
||||||
InvenTreeInternalBarcodePlugin(),
|
InvenTreeInternalBarcodePlugin(),
|
||||||
InvenTreeExternalBarcodePlugin(),
|
|
||||||
] + registry.with_mixin('barcode')
|
] + registry.with_mixin('barcode')
|
||||||
|
|
||||||
barcode_hash = hash_barcode(barcode_data)
|
barcode_hash = hash_barcode(barcode_data)
|
||||||
@ -115,7 +114,6 @@ class BarcodeAssign(APIView):
|
|||||||
# Here we only check against 'InvenTree' plugins
|
# Here we only check against 'InvenTree' plugins
|
||||||
plugins = [
|
plugins = [
|
||||||
InvenTreeInternalBarcodePlugin(),
|
InvenTreeInternalBarcodePlugin(),
|
||||||
InvenTreeExternalBarcodePlugin(),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# First check if the provided barcode matches an existing database entry
|
# First check if the provided barcode matches an existing database entry
|
||||||
@ -133,7 +131,7 @@ class BarcodeAssign(APIView):
|
|||||||
|
|
||||||
valid_labels = []
|
valid_labels = []
|
||||||
|
|
||||||
for model in InvenTreeExternalBarcodePlugin.get_supported_barcode_models():
|
for model in InvenTreeInternalBarcodePlugin.get_supported_barcode_models():
|
||||||
label = model.barcode_model_type()
|
label = model.barcode_model_type()
|
||||||
valid_labels.append(label)
|
valid_labels.append(label)
|
||||||
|
|
||||||
@ -188,7 +186,7 @@ class BarcodeUnassign(APIView):
|
|||||||
"""Respond to a barcode unassign POST request"""
|
"""Respond to a barcode unassign POST request"""
|
||||||
|
|
||||||
# The following database models support assignment of third-party barcodes
|
# The following database models support assignment of third-party barcodes
|
||||||
supported_models = InvenTreeExternalBarcodePlugin.get_supported_barcode_models()
|
supported_models = InvenTreeInternalBarcodePlugin.get_supported_barcode_models()
|
||||||
|
|
||||||
supported_labels = [model.barcode_model_type() for model in supported_models]
|
supported_labels = [model.barcode_model_type() for model in supported_models]
|
||||||
model_names = ', '.join(supported_labels)
|
model_names = ', '.join(supported_labels)
|
||||||
|
@ -63,6 +63,7 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin):
|
|||||||
"""Builtin BarcodePlugin for matching and generating internal barcodes."""
|
"""Builtin BarcodePlugin for matching and generating internal barcodes."""
|
||||||
|
|
||||||
NAME = "InvenTreeInternalBarcode"
|
NAME = "InvenTreeInternalBarcode"
|
||||||
|
TITLE = "Inventree Barcodes"
|
||||||
|
|
||||||
def scan(self, barcode_data):
|
def scan(self, barcode_data):
|
||||||
"""Scan a barcode against this plugin.
|
"""Scan a barcode against this plugin.
|
||||||
@ -83,6 +84,8 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin):
|
|||||||
if type(barcode_data) is not dict:
|
if type(barcode_data) is not dict:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
barcode_hash = hash_barcode(barcode_data)
|
||||||
|
|
||||||
# Look for various matches. First good match will be returned
|
# Look for various matches. First good match will be returned
|
||||||
for model in self.get_supported_barcode_models():
|
for model in self.get_supported_barcode_models():
|
||||||
label = model.barcode_model_type()
|
label = model.barcode_model_type()
|
||||||
@ -93,22 +96,9 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin):
|
|||||||
except (ValueError, model.DoesNotExist):
|
except (ValueError, model.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# If no "direct" hits are found, look for assigned third-party barcodes
|
||||||
class InvenTreeExternalBarcodePlugin(InvenTreeBarcodePlugin):
|
|
||||||
"""Builtin BarcodePlugin for matching arbitrary external barcodes."""
|
|
||||||
|
|
||||||
NAME = "InvenTreeExternalBarcode"
|
|
||||||
|
|
||||||
def scan(self, barcode_data):
|
|
||||||
"""Scan a barcode against this plugin.
|
|
||||||
|
|
||||||
Here we are looking for a dict object which contains a reference to a particular InvenTree databse object
|
|
||||||
"""
|
|
||||||
|
|
||||||
for model in self.get_supported_barcode_models():
|
for model in self.get_supported_barcode_models():
|
||||||
label = model.barcode_model_type()
|
label = model.get_barcode_model_type()
|
||||||
|
|
||||||
barcode_hash = hash_barcode(barcode_data)
|
|
||||||
|
|
||||||
instance = model.lookup_barcode(barcode_hash)
|
instance = model.lookup_barcode(barcode_hash)
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ class MetaBase:
|
|||||||
"""Return True if this plugin is currently active."""
|
"""Return True if this plugin is currently active."""
|
||||||
|
|
||||||
# Builtin plugins are always considered "active"
|
# Builtin plugins are always considered "active"
|
||||||
if self.is_builtin():
|
if self.is_builtin:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
cfg = self.plugin_config()
|
cfg = self.plugin_config()
|
||||||
|
@ -58,14 +58,16 @@
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{% plugin_list as pl_list %}
|
{% plugin_list as pl_list %}
|
||||||
|
{% if pl_list %}
|
||||||
|
<tr><td colspan="6"><h6>{% trans 'Active plugins' %}</h6></td></tr>
|
||||||
{% for plugin_key, plugin in pl_list.items %}
|
{% for plugin_key, plugin in pl_list.items %}
|
||||||
{% include "InvenTree/settings/plugin_details.html" with plugin=plugin plugin_key=plugin_key %}
|
{% include "InvenTree/settings/plugin_details.html" with plugin=plugin plugin_key=plugin_key %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% inactive_plugin_list as in_pl_list %}
|
{% inactive_plugin_list as in_pl_list %}
|
||||||
{% if in_pl_list %}
|
{% if in_pl_list %}
|
||||||
<tr><td colspan="5"></td></tr>
|
<tr><td colspan="6"><h6>{% trans 'Inactive plugins' %}</h6></td></tr>
|
||||||
<tr><td colspan="5"><h6>{% trans 'Inactive plugins' %}</h6></td></tr>
|
|
||||||
{% for plugin_key, plugin in in_pl_list.items %}
|
{% for plugin_key, plugin in in_pl_list.items %}
|
||||||
{% include "InvenTree/settings/plugin_details.html" with plugin=plugin plugin_key=plugin_key %}
|
{% include "InvenTree/settings/plugin_details.html" with plugin=plugin plugin_key=plugin_key %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -3,6 +3,12 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
{% if plugin.is_active %}
|
||||||
|
<span class='fas fa-check-circle icon-green'></span>
|
||||||
|
{% else %}
|
||||||
|
<span class='fas fa-times-circle icon-red'></span>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if plugin.human_name %}
|
{% if plugin.human_name %}
|
||||||
{{ plugin.human_name }}
|
{{ plugin.human_name }}
|
||||||
{% elif plugin.name %}
|
{% elif plugin.name %}
|
||||||
|
@ -42,8 +42,6 @@
|
|||||||
{% include "InvenTree/settings/po.html" %}
|
{% include "InvenTree/settings/po.html" %}
|
||||||
{% include "InvenTree/settings/so.html" %}
|
{% include "InvenTree/settings/so.html" %}
|
||||||
|
|
||||||
{% plugins_enabled as plug %}
|
|
||||||
{% if plug %}
|
|
||||||
{% include "InvenTree/settings/plugin.html" %}
|
{% include "InvenTree/settings/plugin.html" %}
|
||||||
{% plugin_list as pl_list %}
|
{% plugin_list as pl_list %}
|
||||||
{% for plugin_key, plugin in pl_list.items %}
|
{% for plugin_key, plugin in pl_list.items %}
|
||||||
@ -51,7 +49,6 @@
|
|||||||
{% include "InvenTree/settings/plugin_settings.html" %}
|
{% include "InvenTree/settings/plugin_settings.html" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -51,8 +51,6 @@
|
|||||||
{% trans "Sales Orders" as text %}
|
{% trans "Sales Orders" as text %}
|
||||||
{% include "sidebar_item.html" with label='sales-order' text=text icon="fa-truck" %}
|
{% include "sidebar_item.html" with label='sales-order' text=text icon="fa-truck" %}
|
||||||
|
|
||||||
{% plugins_enabled as plug %}
|
|
||||||
{% if plug %}
|
|
||||||
{% include "sidebar_header.html" with text="Plugin Settings" %}
|
{% include "sidebar_header.html" with text="Plugin Settings" %}
|
||||||
{% include "sidebar_item.html" with label='plugin' text="Plugins" icon="fa-plug" %}
|
{% include "sidebar_item.html" with label='plugin' text="Plugins" icon="fa-plug" %}
|
||||||
|
|
||||||
@ -62,6 +60,5 @@
|
|||||||
{% include "sidebar_item.html" with label='plugin-'|add:plugin_key text=plugin.human_name %}
|
{% include "sidebar_item.html" with label='plugin-'|add:plugin_key text=plugin.human_name %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user