Consolidate InvenTree barcode plugins into single plugin class

This commit is contained in:
Oliver Walters 2022-11-01 23:43:55 +11:00
parent 53007dc416
commit eee1464241
7 changed files with 20 additions and 30 deletions

View File

@ -11,8 +11,8 @@ from rest_framework.views import APIView
from InvenTree.helpers import hash_barcode
from plugin import registry
from plugin.builtin.barcodes.inventree_barcode import (
InvenTreeExternalBarcodePlugin, InvenTreeInternalBarcodePlugin)
from plugin.builtin.barcodes.inventree_barcode import \
InvenTreeInternalBarcodePlugin
from users.models import RuleSet
@ -56,7 +56,6 @@ class BarcodeScan(APIView):
# Ensure that the default barcode handlers are run first
plugins = [
InvenTreeInternalBarcodePlugin(),
InvenTreeExternalBarcodePlugin(),
] + registry.with_mixin('barcode')
barcode_hash = hash_barcode(barcode_data)
@ -115,7 +114,6 @@ class BarcodeAssign(APIView):
# Here we only check against 'InvenTree' plugins
plugins = [
InvenTreeInternalBarcodePlugin(),
InvenTreeExternalBarcodePlugin(),
]
# First check if the provided barcode matches an existing database entry
@ -133,7 +131,7 @@ class BarcodeAssign(APIView):
valid_labels = []
for model in InvenTreeExternalBarcodePlugin.get_supported_barcode_models():
for model in InvenTreeInternalBarcodePlugin.get_supported_barcode_models():
label = model.barcode_model_type()
valid_labels.append(label)
@ -188,7 +186,7 @@ class BarcodeUnassign(APIView):
"""Respond to a barcode unassign POST request"""
# 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]
model_names = ', '.join(supported_labels)

View File

@ -63,6 +63,7 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin):
"""Builtin BarcodePlugin for matching and generating internal barcodes."""
NAME = "InvenTreeInternalBarcode"
TITLE = "Inventree Barcodes"
def scan(self, barcode_data):
"""Scan a barcode against this plugin.
@ -83,6 +84,8 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin):
if type(barcode_data) is not dict:
return None
barcode_hash = hash_barcode(barcode_data)
# Look for various matches. First good match will be returned
for model in self.get_supported_barcode_models():
label = model.barcode_model_type()
@ -93,22 +96,9 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin):
except (ValueError, model.DoesNotExist):
pass
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
"""
# If no "direct" hits are found, look for assigned third-party barcodes
for model in self.get_supported_barcode_models():
label = model.barcode_model_type()
barcode_hash = hash_barcode(barcode_data)
label = model.get_barcode_model_type()
instance = model.lookup_barcode(barcode_hash)

View File

@ -108,7 +108,7 @@ class MetaBase:
"""Return True if this plugin is currently active."""
# Builtin plugins are always considered "active"
if self.is_builtin():
if self.is_builtin:
return True
cfg = self.plugin_config()

View File

@ -58,14 +58,16 @@
<tbody>
{% 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 %}
{% include "InvenTree/settings/plugin_details.html" with plugin=plugin plugin_key=plugin_key %}
{% endfor %}
{% endif %}
{% inactive_plugin_list as in_pl_list %}
{% if in_pl_list %}
<tr><td colspan="5"></td></tr>
<tr><td colspan="5"><h6>{% trans 'Inactive plugins' %}</h6></td></tr>
<tr><td colspan="6"><h6>{% trans 'Inactive plugins' %}</h6></td></tr>
{% for plugin_key, plugin in in_pl_list.items %}
{% include "InvenTree/settings/plugin_details.html" with plugin=plugin plugin_key=plugin_key %}
{% endfor %}

View File

@ -3,6 +3,12 @@
<tr>
<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 %}
{{ plugin.human_name }}
{% elif plugin.name %}

View File

@ -42,8 +42,6 @@
{% include "InvenTree/settings/po.html" %}
{% include "InvenTree/settings/so.html" %}
{% plugins_enabled as plug %}
{% if plug %}
{% include "InvenTree/settings/plugin.html" %}
{% plugin_list as pl_list %}
{% for plugin_key, plugin in pl_list.items %}
@ -51,7 +49,6 @@
{% include "InvenTree/settings/plugin_settings.html" %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}

View File

@ -51,8 +51,6 @@
{% trans "Sales Orders" as text %}
{% 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_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 %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}