diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 3032b328bd..6dad393349 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -315,7 +315,7 @@ def WrapWithQuotes(text, quote='"'): return text -def MakeBarcode(object_name, object_pk, object_data={}, **kwargs): +def MakeBarcode(object_name, object_pk, object_data=None, **kwargs): """ Generate a string for a barcode. Adds some global InvenTree parameters. Args: @@ -327,6 +327,8 @@ def MakeBarcode(object_name, object_pk, object_data={}, **kwargs): Returns: json string of the supplied data plus some other data """ + if object_data is None: + object_data = {} url = kwargs.get('url', False) brief = kwargs.get('brief', True) diff --git a/InvenTree/barcodes/api.py b/InvenTree/barcodes/api.py index 355fcab0e1..0d3656ce4c 100644 --- a/InvenTree/barcodes/api.py +++ b/InvenTree/barcodes/api.py @@ -109,14 +109,14 @@ class BarcodeScan(APIView): # No plugin is found! # However, the hash of the barcode may still be associated with a StockItem! else: - hash = hash_barcode(barcode_data) + result_hash = hash_barcode(barcode_data) - response['hash'] = hash + response['hash'] = result_hash response['plugin'] = None # Try to look for a matching StockItem try: - item = StockItem.objects.get(uid=hash) + item = StockItem.objects.get(uid=result_hash) serializer = StockItemSerializer(item, part_detail=True, location_detail=True, supplier_part_detail=True) response['stockitem'] = serializer.data response['url'] = reverse('stock-item-detail', kwargs={'pk': item.id}) @@ -182,8 +182,8 @@ class BarcodeAssign(APIView): # Matching plugin was found if plugin is not None: - hash = plugin.hash() - response['hash'] = hash + result_hash = plugin.hash() + response['hash'] = result_hash response['plugin'] = plugin.name # Ensure that the barcode does not already match a database entry @@ -208,14 +208,14 @@ class BarcodeAssign(APIView): match_found = True else: - hash = hash_barcode(barcode_data) + result_hash = hash_barcode(barcode_data) - response['hash'] = hash + response['hash'] = result_hash response['plugin'] = None # Lookup stock item by hash try: - item = StockItem.objects.get(uid=hash) + item = StockItem.objects.get(uid=result_hash) response['error'] = _('Barcode hash already matches Stock Item') match_found = True except StockItem.DoesNotExist: diff --git a/InvenTree/barcodes/tests.py b/InvenTree/barcodes/tests.py index 1d8f53ec4c..a9795c3928 100644 --- a/InvenTree/barcodes/tests.py +++ b/InvenTree/barcodes/tests.py @@ -124,12 +124,12 @@ class BarcodeAPITest(APITestCase): self.assertIn('success', data) - hash = data['hash'] + result_hash = data['hash'] # Read the item out from the database again item = StockItem.objects.get(pk=522) - self.assertEqual(hash, item.uid) + self.assertEqual(result_hash, item.uid) # Ensure that the same UID cannot be assigned to a different stock item! response = self.client.post( diff --git a/InvenTree/build/test_api.py b/InvenTree/build/test_api.py index 1e0c2b4792..9c20dea580 100644 --- a/InvenTree/build/test_api.py +++ b/InvenTree/build/test_api.py @@ -193,7 +193,7 @@ class BuildOutputCompleteTest(BuildAPITest): self.assertTrue('accept_unallocated' in response.data) # Accept unallocated stock - response = self.post( + self.post( finish_url, { 'accept_unallocated': True, diff --git a/InvenTree/common/api.py b/InvenTree/common/api.py index 65cdea90c5..7c246c46d5 100644 --- a/InvenTree/common/api.py +++ b/InvenTree/common/api.py @@ -66,7 +66,6 @@ class WebhookView(CsrfExemptMixin, APIView): message, ) - # return results data = self.webhook.get_return(payload, headers, request) return HttpResponse(data) diff --git a/InvenTree/common/files.py b/InvenTree/common/files.py index 39c97dca6c..e58b977f2c 100644 --- a/InvenTree/common/files.py +++ b/InvenTree/common/files.py @@ -9,8 +9,6 @@ import os from django.utils.translation import gettext_lazy as _ from django.core.exceptions import ValidationError -# from company.models import ManufacturerPart, SupplierPart - class FileManager: """ Class for managing an uploaded file """ diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index e60de3a33f..261f6edaff 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1475,11 +1475,9 @@ class WebhookEndpoint(models.Model): def process_webhook(self): if self.token: - self.token = self.token self.verify = VerificationMethod.TOKEN # TODO make a object-setting if self.secret: - self.secret = self.secret self.verify = VerificationMethod.HMAC # TODO make a object-setting return True @@ -1489,6 +1487,7 @@ class WebhookEndpoint(models.Model): # no token if self.verify == VerificationMethod.NONE: + # do nothing as no method was chosen pass # static token diff --git a/InvenTree/common/tests.py b/InvenTree/common/tests.py index a02793fb12..c82ca41f38 100644 --- a/InvenTree/common/tests.py +++ b/InvenTree/common/tests.py @@ -10,6 +10,8 @@ from django.contrib.auth import get_user_model from .models import InvenTreeSetting, WebhookEndpoint, WebhookMessage, NotificationEntry from .api import WebhookView +CONTENT_TYPE_JSON = 'application/json' + class SettingsTest(TestCase): """ @@ -105,7 +107,7 @@ class WebhookMessageTests(TestCase): def test_missing_token(self): response = self.client.post( self.url, - content_type='application/json', + content_type=CONTENT_TYPE_JSON, ) assert response.status_code == HTTPStatus.FORBIDDEN @@ -116,7 +118,7 @@ class WebhookMessageTests(TestCase): def test_bad_token(self): response = self.client.post( self.url, - content_type='application/json', + content_type=CONTENT_TYPE_JSON, **{'HTTP_TOKEN': '1234567fghj'}, ) @@ -126,7 +128,7 @@ class WebhookMessageTests(TestCase): def test_bad_url(self): response = self.client.post( '/api/webhook/1234/', - content_type='application/json', + content_type=CONTENT_TYPE_JSON, ) assert response.status_code == HTTPStatus.NOT_FOUND @@ -135,7 +137,7 @@ class WebhookMessageTests(TestCase): response = self.client.post( self.url, data="{'this': 123}", - content_type='application/json', + content_type=CONTENT_TYPE_JSON, **{'HTTP_TOKEN': str(self.endpoint_def.token)}, ) @@ -152,7 +154,7 @@ class WebhookMessageTests(TestCase): # check response = self.client.post( self.url, - content_type='application/json', + content_type=CONTENT_TYPE_JSON, ) assert response.status_code == HTTPStatus.OK @@ -167,7 +169,7 @@ class WebhookMessageTests(TestCase): # check response = self.client.post( self.url, - content_type='application/json', + content_type=CONTENT_TYPE_JSON, ) assert response.status_code == HTTPStatus.FORBIDDEN @@ -182,7 +184,7 @@ class WebhookMessageTests(TestCase): # check response = self.client.post( self.url, - content_type='application/json', + content_type=CONTENT_TYPE_JSON, **{'HTTP_TOKEN': str('68MXtc/OiXdA5e2Nq9hATEVrZFpLb3Zb0oau7n8s31I=')}, ) @@ -193,7 +195,7 @@ class WebhookMessageTests(TestCase): response = self.client.post( self.url, data={"this": "is a message"}, - content_type='application/json', + content_type=CONTENT_TYPE_JSON, **{'HTTP_TOKEN': str(self.endpoint_def.token)}, ) diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 3eb5566a1e..33044d8440 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -92,5 +92,4 @@ class OrderMatchItemForm(MatchItemForm): default_amount=clean_decimal(row.get('purchase_price', '')), ) - # return default return super().get_special_field(col_guess, row, file_manager) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 0625a717a5..d146c3d7b3 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -446,10 +446,10 @@ class PartSerialNumberDetail(generics.RetrieveAPIView): } if latest is not None: - next = increment(latest) + next_serial = increment(latest) - if next != increment: - data['next'] = next + if next_serial != increment: + data['next'] = next_serial return Response(data) diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index c4c7d29228..8925c6d9bd 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -75,7 +75,6 @@ class BomMatchItemForm(MatchItemForm): }) ) - # return default return super().get_special_field(col_guess, row, file_manager) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index fde9c80720..d186a9b5e7 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1530,15 +1530,15 @@ class Part(MPTTModel): returns a string representation of a hash object which can be compared with a stored value """ - hash = hashlib.md5(str(self.id).encode()) + result_hash = hashlib.md5(str(self.id).encode()) # List *all* BOM items (including inherited ones!) bom_items = self.get_bom_items().all().prefetch_related('sub_part') for item in bom_items: - hash.update(str(item.get_item_hash()).encode()) + result_hash.update(str(item.get_item_hash()).encode()) - return str(hash.digest()) + return str(result_hash.digest()) def is_bom_valid(self): """ Check if the BOM is 'valid' - if the calculated checksum matches the stored value @@ -2188,9 +2188,7 @@ def after_save_part(sender, instance: Part, created, **kwargs): Function to be executed after a Part is saved """ - if created: - pass - else: + if not created: # Check part stock only if we are *updating* the part (not creating it) # Run this check in the background @@ -2678,18 +2676,18 @@ class BomItem(models.Model): """ # Seed the hash with the ID of this BOM item - hash = hashlib.md5(str(self.id).encode()) + result_hash = hashlib.md5(str(self.id).encode()) # Update the hash based on line information - hash.update(str(self.sub_part.id).encode()) - hash.update(str(self.sub_part.full_name).encode()) - hash.update(str(self.quantity).encode()) - hash.update(str(self.note).encode()) - hash.update(str(self.reference).encode()) - hash.update(str(self.optional).encode()) - hash.update(str(self.inherited).encode()) + result_hash.update(str(self.sub_part.id).encode()) + result_hash.update(str(self.sub_part.full_name).encode()) + result_hash.update(str(self.quantity).encode()) + result_hash.update(str(self.note).encode()) + result_hash.update(str(self.reference).encode()) + result_hash.update(str(self.optional).encode()) + result_hash.update(str(self.inherited).encode()) - return str(hash.digest()) + return str(result_hash.digest()) def validate_hash(self, valid=True): """ Mark this item as 'valid' (store the checksum hash). diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 64b8b8536f..627b925e23 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -293,7 +293,7 @@ def progress_bar(val, max, *args, **kwargs): Render a progress bar element """ - id = kwargs.get('id', 'progress-bar') + item_id = kwargs.get('id', 'progress-bar') if val > max: style = 'progress-bar-over' @@ -317,7 +317,7 @@ def progress_bar(val, max, *args, **kwargs): style_tags.append(f'max-width: {max_width};') html = f""" -
+
{val} / {max}
diff --git a/InvenTree/part/test_part.py b/InvenTree/part/test_part.py index 6397b9162f..7c9eec983c 100644 --- a/InvenTree/part/test_part.py +++ b/InvenTree/part/test_part.py @@ -30,8 +30,8 @@ class TemplateTagTest(TestCase): self.assertEqual(type(inventree_extras.inventree_version()), str) def test_hash(self): - hash = inventree_extras.inventree_commit_hash() - self.assertGreater(len(hash), 5) + result_hash = inventree_extras.inventree_commit_hash() + self.assertGreater(len(result_hash), 5) def test_date(self): d = inventree_extras.inventree_commit_date() diff --git a/InvenTree/part/test_supplier_part.py b/InvenTree/part/test_supplier_part.py deleted file mode 100644 index c34b788257..0000000000 --- a/InvenTree/part/test_supplier_part.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.test import TestCase - - -class SupplierPartTest(TestCase): - - def setUp(self): - pass diff --git a/InvenTree/plugin/builtin/barcode/mixins.py b/InvenTree/plugin/builtin/barcode/mixins.py index b86130f71e..693df4b662 100644 --- a/InvenTree/plugin/builtin/barcode/mixins.py +++ b/InvenTree/plugin/builtin/barcode/mixins.py @@ -25,8 +25,8 @@ def hash_barcode(barcode_data): barcode_data = ''.join(list(printable_chars)) - hash = hashlib.md5(str(barcode_data).encode()) - return str(hash.hexdigest()) + result_hash = hashlib.md5(str(barcode_data).encode()) + return str(result_hash.hexdigest()) class BarcodeMixin: diff --git a/InvenTree/plugin/integration.py b/InvenTree/plugin/integration.py index 33afae852c..ccf1f6d2eb 100644 --- a/InvenTree/plugin/integration.py +++ b/InvenTree/plugin/integration.py @@ -173,8 +173,8 @@ class IntegrationPluginBase(MixinBase, plugin_base.InvenTreePluginBase): """ License of plugin """ - license = getattr(self, 'LICENSE', None) - return license + lic = getattr(self, 'LICENSE', None) + return lic # endregion @property diff --git a/InvenTree/plugin/models.py b/InvenTree/plugin/models.py index d6fd71d7c4..e33d452e0a 100644 --- a/InvenTree/plugin/models.py +++ b/InvenTree/plugin/models.py @@ -94,10 +94,8 @@ class PluginConfig(models.Model): ret = super().save(force_insert, force_update, *args, **kwargs) if not reload: - if self.active is False and self.__org_active is True: - registry.reload_plugins() - - elif self.active is True and self.__org_active is False: + if (self.active is False and self.__org_active is True) or \ + (self.active is True and self.__org_active is False): registry.reload_plugins() return ret diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 4b7f12bc6c..2cd8311e0f 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -390,6 +390,10 @@ class PluginsRegistry: logger.warning("activate_integration_schedule failed, database not ready") def deactivate_integration_schedule(self): + """ + Deactivate ScheduleMixin + currently nothing is done + """ pass def activate_integration_app(self, plugins, force_reload=False): diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 140bd9c8e3..8a68eb5940 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -1022,7 +1022,7 @@ class StockItem(MPTTModel): def has_tracking_info(self): return self.tracking_info_count > 0 - def add_tracking_entry(self, entry_type, user, deltas={}, notes='', **kwargs): + def add_tracking_entry(self, entry_type, user, deltas=None, notes='', **kwargs): """ Add a history tracking entry for this StockItem @@ -1033,6 +1033,8 @@ class StockItem(MPTTModel): notes - User notes associated with this tracking entry url - Optional URL associated with this tracking entry """ + if deltas is None: + deltas = {} # Has a location been specified? location = kwargs.get('location', None)