mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
make operators simpler
This commit is contained in:
parent
af8bddf690
commit
77aeecf23a
@ -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')
|
||||||
})
|
})
|
||||||
|
@ -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
|
||||||
|
@ -132,7 +132,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):
|
||||||
|
@ -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"),
|
||||||
})
|
})
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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:
|
||||||
|
@ -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")
|
||||||
})
|
})
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
@ -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))
|
||||||
@ -1314,10 +1314,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
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user