From 68d182d67b37559d3391f1f84a77fd5b70e835fb Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Feb 2022 04:23:19 +0100 Subject: [PATCH 1/6] remove unused code --- InvenTree/part/test_bom_import.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/InvenTree/part/test_bom_import.py b/InvenTree/part/test_bom_import.py index 8903660f39..c0a08c2abd 100644 --- a/InvenTree/part/test_bom_import.py +++ b/InvenTree/part/test_bom_import.py @@ -41,7 +41,7 @@ class BomUploadTest(InvenTreeAPITestCase): assembly=False, ) - def post_bom(self, filename, file_data, part=None, clear_existing=None, expected_code=None, content_type='text/plain'): + def post_bom(self, filename, file_data, clear_existing=None, expected_code=None, content_type='text/plain'): bom_file = SimpleUploadedFile( filename, @@ -49,9 +49,6 @@ class BomUploadTest(InvenTreeAPITestCase): content_type=content_type, ) - if part is None: - part = self.part.pk - if clear_existing is None: clear_existing = False From 1ff6988ffd9320327bbe3e40c54d04655ceb6037 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Feb 2022 04:24:13 +0100 Subject: [PATCH 2/6] remove unneeded assignment --- InvenTree/part/test_bom_import.py | 2 +- InvenTree/stock/test_api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/test_bom_import.py b/InvenTree/part/test_bom_import.py index c0a08c2abd..6f9006d487 100644 --- a/InvenTree/part/test_bom_import.py +++ b/InvenTree/part/test_bom_import.py @@ -186,7 +186,7 @@ class BomUploadTest(InvenTreeAPITestCase): self.assertIn('No part column specified', str(response.data)) - response = self.post( + self.post( url, { 'rows': rows, diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index 1e09dec907..a9dbe9e723 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -393,7 +393,7 @@ class StockItemTest(StockAPITestCase): self.assertEqual(trackable_part.get_stock_count(), 0) # This should fail, incorrect serial number count - response = self.post( + self.post( self.list_url, data={ 'part': trackable_part.pk, From 306725ef92db72440719a2003e48187a0688c56a Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Feb 2022 04:25:17 +0100 Subject: [PATCH 3/6] merge satement --- InvenTree/stock/api.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 9723e01c09..fb1cc5f2ba 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -516,9 +516,7 @@ class StockList(generics.ListCreateAPIView): data['location'] = location.pk # An expiry date was *not* specified - try to infer it! - if 'expiry_date' not in data: - - if part.default_expiry > 0: + if 'expiry_date' not in data and part.default_expiry > 0: data['expiry_date'] = datetime.now().date() + timedelta(days=part.default_expiry) # Attempt to extract serial numbers from submitted data From d5bcd256f6c21363b6a22af4fcda3fd3f261967e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Feb 2022 04:26:52 +0100 Subject: [PATCH 4/6] merge statments --- InvenTree/part/serializers.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 549b546a5b..d3956f3c6c 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -789,21 +789,20 @@ class BomImportExtractSerializer(DataFileExtractSerializer): pass # No direct match, where else can we look? - if part is None: - if part_name or part_ipn: - queryset = Part.objects.all() + if part is None and (part_name or part_ipn): + queryset = Part.objects.all() - if part_name: - queryset = queryset.filter(name=part_name) + if part_name: + queryset = queryset.filter(name=part_name) - if part_ipn: - queryset = queryset.filter(IPN=part_ipn) + if part_ipn: + queryset = queryset.filter(IPN=part_ipn) - if queryset.exists(): - if queryset.count() == 1: - part = queryset.first() - else: - row['errors']['part'] = _('Multiple matching parts found') + if queryset.exists(): + if queryset.count() == 1: + part = queryset.first() + else: + row['errors']['part'] = _('Multiple matching parts found') if part is None: row['errors']['part'] = _('No matching part found') From e9b501f7ebcd4ac7aff3cb2d11bbcb6ca60835c3 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Feb 2022 04:29:46 +0100 Subject: [PATCH 5/6] remove unneeded continue --- InvenTree/InvenTree/helpers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 6dad393349..2595f8b5c3 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -475,7 +475,6 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int): continue else: errors.append(_("Invalid group: {g}").format(g=group)) - continue # plus signals either # 1: 'start+': expected number of serials, starting at start @@ -500,7 +499,6 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int): # no case else: errors.append(_("Invalid group: {g}").format(g=group)) - continue # Group should be a number elif group: From ebd54045ecd01eafc1e6f5fdae387c0eaf14ef36 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Feb 2022 04:40:18 +0100 Subject: [PATCH 6/6] PEP fix --- InvenTree/stock/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index fb1cc5f2ba..ed7a4b8c40 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -517,7 +517,7 @@ class StockList(generics.ListCreateAPIView): # An expiry date was *not* specified - try to infer it! if 'expiry_date' not in data and part.default_expiry > 0: - data['expiry_date'] = datetime.now().date() + timedelta(days=part.default_expiry) + data['expiry_date'] = datetime.now().date() + timedelta(days=part.default_expiry) # Attempt to extract serial numbers from submitted data serials = None