From 77aeecf23a51112c4ada1398cf15c5697cca11d5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 15 May 2022 17:52:23 +0200 Subject: [PATCH] make operators simpler --- InvenTree/build/models.py | 4 ++-- InvenTree/common/files.py | 2 +- InvenTree/common/tests.py | 2 +- InvenTree/company/models.py | 2 +- InvenTree/company/views.py | 2 +- InvenTree/label/apps.py | 6 +++--- InvenTree/order/models.py | 10 +++++----- InvenTree/part/models.py | 4 ++-- InvenTree/part/views.py | 2 +- InvenTree/report/models.py | 2 +- InvenTree/stock/models.py | 10 +++++----- ci/check_version_number.py | 4 ++-- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index a1517d73dd..0d7f6e3870 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -777,7 +777,7 @@ class Build(MPTTModel, ReferenceIndexingMixin): if not output.is_building: raise ValidationError(_("Build output is already completed")) - if not output.build == self: + if output.build != self: raise ValidationError(_("Build output does not match Build Order")) # Unallocate all build items against the output @@ -1240,7 +1240,7 @@ class BuildItem(models.Model): }) # Quantity must be 1 for serialized stock - if self.stock_item.serialized and not self.quantity == 1: + if self.stock_item.serialized and self.quantity != 1: raise ValidationError({ 'quantity': _('Quantity must be 1 for serialized stock') }) diff --git a/InvenTree/common/files.py b/InvenTree/common/files.py index e58b977f2c..e6d26be10f 100644 --- a/InvenTree/common/files.py +++ b/InvenTree/common/files.py @@ -199,7 +199,7 @@ class FileManager: try: # Excel import casts number-looking-items into floats, which is annoying - if item == int(item) and not str(item) == str(int(item)): + if item == int(item) and str(item) != str(int(item)): data[idx] = int(item) except ValueError: pass diff --git a/InvenTree/common/tests.py b/InvenTree/common/tests.py index 8fa0f3b28e..1e34ff9129 100644 --- a/InvenTree/common/tests.py +++ b/InvenTree/common/tests.py @@ -132,7 +132,7 @@ class SettingsTest(TestCase): if description is None: raise ValueError(f'Missing GLOBAL_SETTING description for {key}') # pragma: no cover - if not key == key.upper(): + if key != key.upper(): raise ValueError(f"SETTINGS key '{key}' is not uppercase") # pragma: no cover def test_defaults(self): diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 9b881c227e..5f6f254e2d 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -494,7 +494,7 @@ class SupplierPart(models.Model): # Ensure that the linked manufacturer_part points to the same part! if self.manufacturer_part and self.part: - if not self.manufacturer_part.part == self.part: + if self.manufacturer_part.part != self.part: raise ValidationError({ 'manufacturer_part': _("Linked manufacturer part must reference the same base part"), }) diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index 6d8279558c..a9e7054b7a 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -162,7 +162,7 @@ class CompanyImageDownloadFromURL(AjaxUpdateView): self.response = response # Check for valid response code - if not response.status_code == 200: + if response.status_code != 200: form.add_error('url', _('Invalid response: {code}').format(code=response.status_code)) return diff --git a/InvenTree/label/apps.py b/InvenTree/label/apps.py index 633907f330..1a719a9638 100644 --- a/InvenTree/label/apps.py +++ b/InvenTree/label/apps.py @@ -105,7 +105,7 @@ class LabelConfig(AppConfig): # File already exists - let's see if it is the "same", # or if we need to overwrite it with a newer copy! - if not hashFile(dst_file) == hashFile(src_file): # pragma: no cover + if hashFile(dst_file) != hashFile(src_file): # pragma: no cover logger.info(f"Hash differs for '{filename}'") to_copy = True @@ -199,7 +199,7 @@ class LabelConfig(AppConfig): # File already exists - let's see if it is the "same", # or if we need to overwrite it with a newer copy! - if not hashFile(dst_file) == hashFile(src_file): # pragma: no cover + if hashFile(dst_file) != hashFile(src_file): # pragma: no cover logger.info(f"Hash differs for '{filename}'") to_copy = True @@ -291,7 +291,7 @@ class LabelConfig(AppConfig): if os.path.exists(dst_file): # File already exists - let's see if it is the "same" - if not hashFile(dst_file) == hashFile(src_file): # pragma: no cover + if hashFile(dst_file) != hashFile(src_file): # pragma: no cover logger.info(f"Hash differs for '{filename}'") to_copy = True diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 6ca5b7a293..1b9aae116c 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -306,7 +306,7 @@ class PurchaseOrder(Order): except ValueError: raise ValidationError({'quantity': _("Invalid quantity provided")}) - if not supplier_part.supplier == self.supplier: + if supplier_part.supplier != self.supplier: raise ValidationError({'supplier': _("Part supplier must match PO supplier")}) if group: @@ -445,7 +445,7 @@ class PurchaseOrder(Order): if barcode is None: barcode = '' - if not self.status == PurchaseOrderStatus.PLACED: + if self.status != PurchaseOrderStatus.PLACED: raise ValidationError( "Lines can only be received against an order marked as 'PLACED'" ) @@ -729,7 +729,7 @@ class SalesOrder(Order): Return True if this order can be cancelled """ - if not self.status == SalesOrderStatus.PENDING: + if self.status != SalesOrderStatus.PENDING: return False return True @@ -1295,7 +1295,7 @@ class SalesOrderAllocation(models.Model): raise ValidationError({'item': _('Stock item has not been assigned')}) try: - if not self.line.part == self.item.part: + if self.line.part != self.item.part: errors['item'] = _('Cannot allocate stock item to a line with a different part') except PartModels.Part.DoesNotExist: errors['line'] = _('Cannot allocate stock to a line without a part') @@ -1310,7 +1310,7 @@ class SalesOrderAllocation(models.Model): if self.quantity <= 0: errors['quantity'] = _('Allocation quantity must be greater than zero') - if self.item.serial and not self.quantity == 1: + if self.item.serial and self.quantity != 1: errors['quantity'] = _('Quantity must be 1 for serialized stock item') if self.line.order != self.shipment.order: diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 492da8f5de..2b083f277b 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -444,7 +444,7 @@ class Part(MPTTModel): previous = Part.objects.get(pk=self.pk) # Image has been changed - if previous.image is not None and not self.image == previous.image: + if previous.image is not None and self.image != previous.image: # Are there any (other) parts which reference the image? n_refs = Part.objects.filter(image=previous.image).exclude(pk=self.pk).count() @@ -2895,7 +2895,7 @@ class BomItem(models.Model, DataImportMixin): # If the sub_part is 'trackable' then the 'quantity' field must be an integer if self.sub_part.trackable: - if not self.quantity == int(self.quantity): + if self.quantity != int(self.quantity): raise ValidationError({ "quantity": _("Quantity must be integer value for trackable parts") }) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index f1d587e206..7b5021fb45 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -628,7 +628,7 @@ class PartImageDownloadFromURL(AjaxUpdateView): self.response = response # Check for valid response code - if not response.status_code == 200: + if response.status_code != 200: form.add_error('url', _('Invalid response: {code}').format(code=response.status_code)) return diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index 32ba9077b1..5fe98a7094 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -389,7 +389,7 @@ class BuildReport(ReportTemplateBase): my_build = self.object_to_print - if not type(my_build) == build.models.Build: + if type(my_build) != build.models.Build: raise TypeError('Provided model is not a Build object') return { diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 53e1321e1a..2c0b9c6fbb 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -404,7 +404,7 @@ class StockItem(MPTTModel): deltas = {} # Status changed? - if not old.status == self.status: + if old.status != self.status: deltas['status'] = self.status # TODO - Other interesting changes we are interested in... @@ -493,7 +493,7 @@ class StockItem(MPTTModel): try: if self.part.trackable: # Trackable parts must have integer values for quantity field! - if not self.quantity == int(self.quantity): + if self.quantity != int(self.quantity): raise ValidationError({ 'quantity': _('Quantity must be integer value for trackable parts') }) @@ -511,7 +511,7 @@ class StockItem(MPTTModel): # The 'supplier_part' field must point to the same part! try: if self.supplier_part is not None: - if not self.supplier_part.part == self.part: + if self.supplier_part.part != self.part: raise ValidationError({'supplier_part': _("Part type ('{pf}') must be {pe}").format( pf=str(self.supplier_part.part), pe=str(self.part)) @@ -1314,10 +1314,10 @@ class StockItem(MPTTModel): if quantity > self.quantity: raise ValidationError({"quantity": _("Quantity must not exceed available stock quantity ({n})").format(n=self.quantity)}) - if not type(serials) in [list, tuple]: + if type(serials) not in [list, tuple]: raise ValidationError({"serial_numbers": _("Serial numbers must be a list of integers")}) - if not quantity == len(serials): + if quantity != len(serials): raise ValidationError({"quantity": _("Quantity does not match serial numbers")}) # Test if each of the serial numbers are valid diff --git a/ci/check_version_number.py b/ci/check_version_number.py index 0514854407..b071afbe86 100644 --- a/ci/check_version_number.py +++ b/ci/check_version_number.py @@ -25,7 +25,7 @@ if __name__ == '__main__': # Extract the InvenTree software version results = re.findall(r'INVENTREE_SW_VERSION = "(.*)"', text) - if not len(results) == 1: + if len(results) != 1: print(f"Could not find INVENTREE_SW_VERSION in {version_file}") sys.exit(1) @@ -91,7 +91,7 @@ if __name__ == '__main__': sys.exit(1) if args.tag: - if not args.tag == version: + if args.tag != version: print(f"Release tag '{args.tag}' does not match INVENTREE_SW_VERSION '{version}'") sys.exit(1)