2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Merge pull request #2975 from matmair/fix-boolean

Fix boolean comparator
This commit is contained in:
Oliver 2022-05-16 07:22:55 +10:00 committed by GitHub
commit c3433128b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 36 additions and 36 deletions

View File

@ -131,7 +131,7 @@ class InvenTreeConfig(AppConfig):
update = True update = True
# Backend currency has changed? # Backend currency has changed?
if not base_currency == backend.base_currency: if base_currency != backend.base_currency:
logger.info(f"Base currency changed from {backend.base_currency} to {base_currency}") logger.info(f"Base currency changed from {backend.base_currency} to {base_currency}")
update = True update = True

View File

@ -224,7 +224,7 @@ def increment(n):
groups = result.groups() groups = result.groups()
# If we cannot match the regex, then simply return the provided value # If we cannot match the regex, then simply return the provided value
if not len(groups) == 2: if len(groups) != 2:
return value return value
prefix, number = groups prefix, number = groups
@ -536,7 +536,7 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
raise ValidationError([_("No serial numbers found")]) raise ValidationError([_("No serial numbers found")])
# The number of extracted serial numbers must match the expected quantity # The number of extracted serial numbers must match the expected quantity
if not expected_quantity == len(numbers): if expected_quantity != len(numbers):
raise ValidationError([_("Number of unique serial numbers ({s}) must match quantity ({q})").format(s=len(numbers), q=expected_quantity)]) raise ValidationError([_("Number of unique serial numbers ({s}) must match quantity ({q})").format(s=len(numbers), q=expected_quantity)])
return numbers return numbers
@ -575,7 +575,7 @@ def validateFilterString(value, model=None):
pair = group.split('=') pair = group.split('=')
if not len(pair) == 2: if len(pair) != 2:
raise ValidationError( raise ValidationError(
"Invalid group: {g}".format(g=group) "Invalid group: {g}".format(g=group)
) )

View File

@ -250,7 +250,7 @@ class InvenTreeMetadata(SimpleMetadata):
field_info = super().get_field_info(field) field_info = super().get_field_info(field)
# If a default value is specified for the serializer field, add it! # If a default value is specified for the serializer field, add it!
if 'default' not in field_info and not field.default == empty: if 'default' not in field_info and field.default != empty:
field_info['default'] = field.get_default() field_info['default'] = field.get_default()
# Force non-nullable fields to read as "required" # Force non-nullable fields to read as "required"

View File

@ -259,7 +259,7 @@ class InvenTreeAttachment(models.Model):
new_file = os.path.abspath(new_file) new_file = os.path.abspath(new_file)
# Check that there are no directory tricks going on... # Check that there are no directory tricks going on...
if not os.path.dirname(new_file) == attachment_dir: if os.path.dirname(new_file) != attachment_dir:
logger.error(f"Attempted to rename attachment outside valid directory: '{new_file}'") logger.error(f"Attempted to rename attachment outside valid directory: '{new_file}'")
raise ValidationError(_("Invalid attachment directory")) raise ValidationError(_("Invalid attachment directory"))

View File

@ -658,7 +658,7 @@ AUTH_PASSWORD_VALIDATORS = [
EXTRA_URL_SCHEMES = CONFIG.get('extra_url_schemes', []) EXTRA_URL_SCHEMES = CONFIG.get('extra_url_schemes', [])
if not type(EXTRA_URL_SCHEMES) in [list]: # pragma: no cover if type(EXTRA_URL_SCHEMES) not in [list]: # pragma: no cover
logger.warning("extra_url_schemes not correctly formatted") logger.warning("extra_url_schemes not correctly formatted")
EXTRA_URL_SCHEMES = [] EXTRA_URL_SCHEMES = []

View File

@ -204,7 +204,7 @@ def check_for_updates():
response = requests.get('https://api.github.com/repos/inventree/inventree/releases/latest') response = requests.get('https://api.github.com/repos/inventree/inventree/releases/latest')
if not response.status_code == 200: if response.status_code != 200:
raise ValueError(f'Unexpected status code from GitHub API: {response.status_code}') raise ValueError(f'Unexpected status code from GitHub API: {response.status_code}')
data = json.loads(response.text) data = json.loads(response.text)
@ -216,13 +216,13 @@ def check_for_updates():
match = re.match(r"^.*(\d+)\.(\d+)\.(\d+).*$", tag) match = re.match(r"^.*(\d+)\.(\d+)\.(\d+).*$", tag)
if not len(match.groups()) == 3: if len(match.groups()) != 3:
logger.warning(f"Version '{tag}' did not match expected pattern") logger.warning(f"Version '{tag}' did not match expected pattern")
return return
latest_version = [int(x) for x in match.groups()] latest_version = [int(x) for x in match.groups()]
if not len(latest_version) == 3: if len(latest_version) != 3:
raise ValueError(f"Version '{tag}' is not correct format") raise ValueError(f"Version '{tag}' is not correct format")
logger.info(f"Latest InvenTree version: '{tag}'") logger.info(f"Latest InvenTree version: '{tag}'")

View File

@ -627,7 +627,7 @@ class SetPasswordView(AjaxUpdateView):
if valid: if valid:
# Passwords must match # Passwords must match
if not p1 == p2: if p1 != p2:
error = _('Password fields must match') error = _('Password fields must match')
form.add_error('enter_password', error) form.add_error('enter_password', error)
form.add_error('confirm_password', error) form.add_error('confirm_password', error)

View File

@ -777,7 +777,7 @@ class Build(MPTTModel, ReferenceIndexingMixin):
if not output.is_building: if not output.is_building:
raise ValidationError(_("Build output is already completed")) 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")) raise ValidationError(_("Build output does not match Build Order"))
# Unallocate all build items against the output # Unallocate all build items against the output
@ -1240,7 +1240,7 @@ class BuildItem(models.Model):
}) })
# Quantity must be 1 for serialized stock # 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({ raise ValidationError({
'quantity': _('Quantity must be 1 for serialized stock') 'quantity': _('Quantity must be 1 for serialized stock')
}) })

View File

@ -199,7 +199,7 @@ class FileManager:
try: try:
# Excel import casts number-looking-items into floats, which is annoying # 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) data[idx] = int(item)
except ValueError: except ValueError:
pass pass

View File

@ -133,7 +133,7 @@ class SettingsTest(TestCase):
if description is None: if description is None:
raise ValueError(f'Missing GLOBAL_SETTING description for {key}') # pragma: no cover 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 raise ValueError(f"SETTINGS key '{key}' is not uppercase") # pragma: no cover
def test_defaults(self): def test_defaults(self):

View File

@ -494,7 +494,7 @@ class SupplierPart(models.Model):
# Ensure that the linked manufacturer_part points to the same part! # Ensure that the linked manufacturer_part points to the same part!
if self.manufacturer_part and self.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({ raise ValidationError({
'manufacturer_part': _("Linked manufacturer part must reference the same base part"), 'manufacturer_part': _("Linked manufacturer part must reference the same base part"),
}) })

View File

@ -162,7 +162,7 @@ class CompanyImageDownloadFromURL(AjaxUpdateView):
self.response = response self.response = response
# Check for valid response code # 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)) form.add_error('url', _('Invalid response: {code}').format(code=response.status_code))
return return

View File

@ -105,7 +105,7 @@ class LabelConfig(AppConfig):
# File already exists - let's see if it is the "same", # File already exists - let's see if it is the "same",
# or if we need to overwrite it with a newer copy! # 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}'") logger.info(f"Hash differs for '{filename}'")
to_copy = True to_copy = True
@ -199,7 +199,7 @@ class LabelConfig(AppConfig):
# File already exists - let's see if it is the "same", # File already exists - let's see if it is the "same",
# or if we need to overwrite it with a newer copy! # 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}'") logger.info(f"Hash differs for '{filename}'")
to_copy = True to_copy = True
@ -291,7 +291,7 @@ class LabelConfig(AppConfig):
if os.path.exists(dst_file): if os.path.exists(dst_file):
# File already exists - let's see if it is the "same" # 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}'") logger.info(f"Hash differs for '{filename}'")
to_copy = True to_copy = True

View File

@ -306,7 +306,7 @@ class PurchaseOrder(Order):
except ValueError: except ValueError:
raise ValidationError({'quantity': _("Invalid quantity provided")}) 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")}) raise ValidationError({'supplier': _("Part supplier must match PO supplier")})
if group: if group:
@ -445,7 +445,7 @@ class PurchaseOrder(Order):
if barcode is None: if barcode is None:
barcode = '' barcode = ''
if not self.status == PurchaseOrderStatus.PLACED: if self.status != PurchaseOrderStatus.PLACED:
raise ValidationError( raise ValidationError(
"Lines can only be received against an order marked as 'PLACED'" "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 Return True if this order can be cancelled
""" """
if not self.status == SalesOrderStatus.PENDING: if self.status != SalesOrderStatus.PENDING:
return False return False
return True return True
@ -1295,7 +1295,7 @@ class SalesOrderAllocation(models.Model):
raise ValidationError({'item': _('Stock item has not been assigned')}) raise ValidationError({'item': _('Stock item has not been assigned')})
try: 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') errors['item'] = _('Cannot allocate stock item to a line with a different part')
except PartModels.Part.DoesNotExist: except PartModels.Part.DoesNotExist:
errors['line'] = _('Cannot allocate stock to a line without a part') errors['line'] = _('Cannot allocate stock to a line without a part')
@ -1310,7 +1310,7 @@ class SalesOrderAllocation(models.Model):
if self.quantity <= 0: if self.quantity <= 0:
errors['quantity'] = _('Allocation quantity must be greater than zero') 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') errors['quantity'] = _('Quantity must be 1 for serialized stock item')
if self.line.order != self.shipment.order: if self.line.order != self.shipment.order:

View File

@ -444,7 +444,7 @@ class Part(MPTTModel):
previous = Part.objects.get(pk=self.pk) previous = Part.objects.get(pk=self.pk)
# Image has been changed # 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? # Are there any (other) parts which reference the image?
n_refs = Part.objects.filter(image=previous.image).exclude(pk=self.pk).count() 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 the sub_part is 'trackable' then the 'quantity' field must be an integer
if self.sub_part.trackable: if self.sub_part.trackable:
if not self.quantity == int(self.quantity): if self.quantity != int(self.quantity):
raise ValidationError({ raise ValidationError({
"quantity": _("Quantity must be integer value for trackable parts") "quantity": _("Quantity must be integer value for trackable parts")
}) })

View File

@ -628,7 +628,7 @@ class PartImageDownloadFromURL(AjaxUpdateView):
self.response = response self.response = response
# Check for valid response code # 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)) form.add_error('url', _('Invalid response: {code}').format(code=response.status_code))
return return

View File

@ -389,7 +389,7 @@ class BuildReport(ReportTemplateBase):
my_build = self.object_to_print 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') raise TypeError('Provided model is not a Build object')
return { return {

View File

@ -404,7 +404,7 @@ class StockItem(MPTTModel):
deltas = {} deltas = {}
# Status changed? # Status changed?
if not old.status == self.status: if old.status != self.status:
deltas['status'] = self.status deltas['status'] = self.status
# TODO - Other interesting changes we are interested in... # TODO - Other interesting changes we are interested in...
@ -493,7 +493,7 @@ class StockItem(MPTTModel):
try: try:
if self.part.trackable: if self.part.trackable:
# Trackable parts must have integer values for quantity field! # Trackable parts must have integer values for quantity field!
if not self.quantity == int(self.quantity): if self.quantity != int(self.quantity):
raise ValidationError({ raise ValidationError({
'quantity': _('Quantity must be integer value for trackable parts') '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! # The 'supplier_part' field must point to the same part!
try: try:
if self.supplier_part is not None: 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( raise ValidationError({'supplier_part': _("Part type ('{pf}') must be {pe}").format(
pf=str(self.supplier_part.part), pf=str(self.supplier_part.part),
pe=str(self.part)) pe=str(self.part))
@ -1321,10 +1321,10 @@ class StockItem(MPTTModel):
if quantity > self.quantity: if quantity > self.quantity:
raise ValidationError({"quantity": _("Quantity must not exceed available stock quantity ({n})").format(n=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")}) 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")}) raise ValidationError({"quantity": _("Quantity does not match serial numbers")})
# Test if each of the serial numbers are valid # Test if each of the serial numbers are valid

View File

@ -25,7 +25,7 @@ if __name__ == '__main__':
# Extract the InvenTree software version # Extract the InvenTree software version
results = re.findall(r'INVENTREE_SW_VERSION = "(.*)"', text) 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}") print(f"Could not find INVENTREE_SW_VERSION in {version_file}")
sys.exit(1) sys.exit(1)
@ -91,7 +91,7 @@ if __name__ == '__main__':
sys.exit(1) sys.exit(1)
if args.tag: 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}'") print(f"Release tag '{args.tag}' does not match INVENTREE_SW_VERSION '{version}'")
sys.exit(1) sys.exit(1)