mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #2975 from matmair/fix-boolean
Fix boolean comparator
This commit is contained in:
commit
c3433128b5
@ -131,7 +131,7 @@ class InvenTreeConfig(AppConfig):
|
||||
update = True
|
||||
|
||||
# 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}")
|
||||
update = True
|
||||
|
||||
|
@ -224,7 +224,7 @@ def increment(n):
|
||||
groups = result.groups()
|
||||
|
||||
# If we cannot match the regex, then simply return the provided value
|
||||
if not len(groups) == 2:
|
||||
if len(groups) != 2:
|
||||
return value
|
||||
|
||||
prefix, number = groups
|
||||
@ -536,7 +536,7 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
|
||||
raise ValidationError([_("No serial numbers found")])
|
||||
|
||||
# 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)])
|
||||
|
||||
return numbers
|
||||
@ -575,7 +575,7 @@ def validateFilterString(value, model=None):
|
||||
|
||||
pair = group.split('=')
|
||||
|
||||
if not len(pair) == 2:
|
||||
if len(pair) != 2:
|
||||
raise ValidationError(
|
||||
"Invalid group: {g}".format(g=group)
|
||||
)
|
||||
|
@ -250,7 +250,7 @@ class InvenTreeMetadata(SimpleMetadata):
|
||||
field_info = super().get_field_info(field)
|
||||
|
||||
# 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()
|
||||
|
||||
# Force non-nullable fields to read as "required"
|
||||
|
@ -259,7 +259,7 @@ class InvenTreeAttachment(models.Model):
|
||||
new_file = os.path.abspath(new_file)
|
||||
|
||||
# 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}'")
|
||||
raise ValidationError(_("Invalid attachment directory"))
|
||||
|
||||
|
@ -658,7 +658,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
|
||||
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")
|
||||
EXTRA_URL_SCHEMES = []
|
||||
|
||||
|
@ -204,7 +204,7 @@ def check_for_updates():
|
||||
|
||||
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}')
|
||||
|
||||
data = json.loads(response.text)
|
||||
@ -216,13 +216,13 @@ def check_for_updates():
|
||||
|
||||
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")
|
||||
return
|
||||
|
||||
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")
|
||||
|
||||
logger.info(f"Latest InvenTree version: '{tag}'")
|
||||
|
@ -627,7 +627,7 @@ class SetPasswordView(AjaxUpdateView):
|
||||
if valid:
|
||||
# Passwords must match
|
||||
|
||||
if not p1 == p2:
|
||||
if p1 != p2:
|
||||
error = _('Password fields must match')
|
||||
form.add_error('enter_password', error)
|
||||
form.add_error('confirm_password', error)
|
||||
|
@ -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')
|
||||
})
|
||||
|
@ -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
|
||||
|
@ -133,7 +133,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):
|
||||
|
@ -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"),
|
||||
})
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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")
|
||||
})
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
@ -1321,10 +1321,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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user