From ef22b9fc1b9f456c75d9882b575e611388badc31 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:47:59 +0100 Subject: [PATCH 01/14] remove unneeded assingments --- InvenTree/common/models.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index e60de3a33f..f9e0339bf6 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 From db6654660698c975de0e4770c2e5293b82aba832 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:49:21 +0100 Subject: [PATCH 02/14] rename to not shadow builtin --- InvenTree/plugin/builtin/barcode/mixins.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: From f8c4470d98f103bfb1851a3f66a609be72318d50 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:51:42 +0100 Subject: [PATCH 03/14] make simpler --- InvenTree/part/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index fde9c80720..1566c1a9f0 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -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 From 9da234002b78097aa077911e773b0ca01721c3cd Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:51:53 +0100 Subject: [PATCH 04/14] add comment --- InvenTree/common/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index f9e0339bf6..261f6edaff 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1487,6 +1487,7 @@ class WebhookEndpoint(models.Model): # no token if self.verify == VerificationMethod.NONE: + # do nothing as no method was chosen pass # static token From 3d2113d98bbd324aaf1a127a9ca3614acc44e338 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:53:50 +0100 Subject: [PATCH 05/14] make simpler --- InvenTree/plugin/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/InvenTree/plugin/models.py b/InvenTree/plugin/models.py index d6fd71d7c4..713d8daf27 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 From 21125eb8929f5f9ef7805b4c478c8f8fdbbe55c3 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:55:07 +0100 Subject: [PATCH 06/14] add docstring --- InvenTree/plugin/registry.py | 4 ++++ 1 file changed, 4 insertions(+) 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): From 967efae8f1f984c0e85479d4cf2b20ae51dff27d Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:55:48 +0100 Subject: [PATCH 07/14] make simpler --- InvenTree/build/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 16239289c0148ee62006e2ebd7452fbf076ec14b Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:56:39 +0100 Subject: [PATCH 08/14] remove dead code --- InvenTree/common/api.py | 1 - 1 file changed, 1 deletion(-) 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) From a96ceba0bebad59167bef9904de592d8d576b7c8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 23:58:36 +0100 Subject: [PATCH 09/14] use constant for content type --- InvenTree/common/tests.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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)}, ) From b2eb4e131aedb01f9bc1c1c040ebe9b38ccded1d Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 21 Jan 2022 00:08:36 +0100 Subject: [PATCH 10/14] remove empty test --- InvenTree/part/test_supplier_part.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 InvenTree/part/test_supplier_part.py 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 From cbd84a23f95b967dbbb2d7df14edf1aa31cbc7cc Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 21 Jan 2022 00:11:26 +0100 Subject: [PATCH 11/14] fix default empy dict --- InvenTree/InvenTree/helpers.py | 4 +++- InvenTree/stock/models.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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/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) From c44565f9e327b3adf54da0a600059f1325d42f86 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 21 Jan 2022 00:17:52 +0100 Subject: [PATCH 12/14] fix reused builtins --- InvenTree/barcodes/api.py | 16 ++++++------- InvenTree/barcodes/tests.py | 4 ++-- InvenTree/part/api.py | 6 ++--- InvenTree/part/models.py | 24 +++++++++---------- .../part/templatetags/inventree_extras.py | 4 ++-- InvenTree/part/test_part.py | 4 ++-- InvenTree/plugin/integration.py | 4 ++-- 7 files changed, 31 insertions(+), 31 deletions(-) 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/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/models.py b/InvenTree/part/models.py index 1566c1a9f0..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 @@ -2676,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/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 From ff897ccc413f4aacd4420a53b2246af44346ac82 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 21 Jan 2022 00:30:51 +0100 Subject: [PATCH 13/14] remove dead code --- InvenTree/common/files.py | 2 -- InvenTree/order/forms.py | 1 - InvenTree/part/forms.py | 1 - 3 files changed, 4 deletions(-) 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/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/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) From 116369bba171751e20ef09db2af51969970468d0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 21 Jan 2022 00:31:03 +0100 Subject: [PATCH 14/14] fix indent --- InvenTree/plugin/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/plugin/models.py b/InvenTree/plugin/models.py index 713d8daf27..e33d452e0a 100644 --- a/InvenTree/plugin/models.py +++ b/InvenTree/plugin/models.py @@ -95,7 +95,7 @@ class PluginConfig(models.Model): if not reload: if (self.active is False and self.__org_active is True) or \ - (self.active is True and self.__org_active is False): + (self.active is True and self.__org_active is False): registry.reload_plugins() return ret