From 4d7407ee512cacfce4df85cf2f8d6c4dd7e0b15d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 14 Apr 2020 23:38:42 +1000 Subject: [PATCH] Logic fix --- InvenTree/InvenTree/api.py | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/InvenTree/InvenTree/api.py b/InvenTree/InvenTree/api.py index b137100327..af66fa6751 100644 --- a/InvenTree/InvenTree/api.py +++ b/InvenTree/InvenTree/api.py @@ -61,30 +61,30 @@ class BarcodeScanView(APIView): if barcode_data is None: response['error'] = _('No barcode data provided') + else: + # Look for a barcode plugin that knows how to handle the data + for plugin_class in barcode_plugins: - # Look for a barcode plugin that knows how to handle the data - for plugin_class in barcode_plugins: + # Instantiate the plugin with the provided plugin data + plugin = plugin_class(barcode_data) - # Instantiate the plugin with the provided plugin data - plugin = plugin_class(barcode_data) + if plugin.validate(): + + # Plugin should return a dict response + response = plugin.decode() + + if type(response) is dict: + if 'success' not in response.keys() and 'error' not in response.keys(): + response['success'] = _('Barcode successfully decoded') + else: + response = { + 'error': _('Barcode plugin returned incorrect response') + } - if plugin.validate(): - - # Plugin should return a dict response - response = plugin.decode() - - if type(response) is dict: - if 'success' not in response.keys() and 'error' not in response.keys(): - response['success'] = _('Barcode successfully decoded') - else: - response = { - 'error': _('Barcode plugin returned incorrect response') - } + response['plugin'] = plugin.get_name() + response['hash'] = plugin.hash() - response['plugin'] = plugin.get_name() - response['hash'] = plugin.hash() - - break + break if 'error' not in response and 'success' not in response: response = {