mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
fix reused builtins
This commit is contained in:
parent
cbd84a23f9
commit
c44565f9e3
@ -109,14 +109,14 @@ class BarcodeScan(APIView):
|
|||||||
# No plugin is found!
|
# No plugin is found!
|
||||||
# However, the hash of the barcode may still be associated with a StockItem!
|
# However, the hash of the barcode may still be associated with a StockItem!
|
||||||
else:
|
else:
|
||||||
hash = hash_barcode(barcode_data)
|
result_hash = hash_barcode(barcode_data)
|
||||||
|
|
||||||
response['hash'] = hash
|
response['hash'] = result_hash
|
||||||
response['plugin'] = None
|
response['plugin'] = None
|
||||||
|
|
||||||
# Try to look for a matching StockItem
|
# Try to look for a matching StockItem
|
||||||
try:
|
try:
|
||||||
item = StockItem.objects.get(uid=hash)
|
item = StockItem.objects.get(uid=result_hash)
|
||||||
serializer = StockItemSerializer(item, part_detail=True, location_detail=True, supplier_part_detail=True)
|
serializer = StockItemSerializer(item, part_detail=True, location_detail=True, supplier_part_detail=True)
|
||||||
response['stockitem'] = serializer.data
|
response['stockitem'] = serializer.data
|
||||||
response['url'] = reverse('stock-item-detail', kwargs={'pk': item.id})
|
response['url'] = reverse('stock-item-detail', kwargs={'pk': item.id})
|
||||||
@ -182,8 +182,8 @@ class BarcodeAssign(APIView):
|
|||||||
# Matching plugin was found
|
# Matching plugin was found
|
||||||
if plugin is not None:
|
if plugin is not None:
|
||||||
|
|
||||||
hash = plugin.hash()
|
result_hash = plugin.hash()
|
||||||
response['hash'] = hash
|
response['hash'] = result_hash
|
||||||
response['plugin'] = plugin.name
|
response['plugin'] = plugin.name
|
||||||
|
|
||||||
# Ensure that the barcode does not already match a database entry
|
# Ensure that the barcode does not already match a database entry
|
||||||
@ -208,14 +208,14 @@ class BarcodeAssign(APIView):
|
|||||||
match_found = True
|
match_found = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
hash = hash_barcode(barcode_data)
|
result_hash = hash_barcode(barcode_data)
|
||||||
|
|
||||||
response['hash'] = hash
|
response['hash'] = result_hash
|
||||||
response['plugin'] = None
|
response['plugin'] = None
|
||||||
|
|
||||||
# Lookup stock item by hash
|
# Lookup stock item by hash
|
||||||
try:
|
try:
|
||||||
item = StockItem.objects.get(uid=hash)
|
item = StockItem.objects.get(uid=result_hash)
|
||||||
response['error'] = _('Barcode hash already matches Stock Item')
|
response['error'] = _('Barcode hash already matches Stock Item')
|
||||||
match_found = True
|
match_found = True
|
||||||
except StockItem.DoesNotExist:
|
except StockItem.DoesNotExist:
|
||||||
|
@ -124,12 +124,12 @@ class BarcodeAPITest(APITestCase):
|
|||||||
|
|
||||||
self.assertIn('success', data)
|
self.assertIn('success', data)
|
||||||
|
|
||||||
hash = data['hash']
|
result_hash = data['hash']
|
||||||
|
|
||||||
# Read the item out from the database again
|
# Read the item out from the database again
|
||||||
item = StockItem.objects.get(pk=522)
|
item = StockItem.objects.get(pk=522)
|
||||||
|
|
||||||
self.assertEqual(hash, item.uid)
|
self.assertEqual(result_hash, item.uid)
|
||||||
|
|
||||||
# Ensure that the same UID cannot be assigned to a different stock item!
|
# Ensure that the same UID cannot be assigned to a different stock item!
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
|
@ -446,10 +446,10 @@ class PartSerialNumberDetail(generics.RetrieveAPIView):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if latest is not None:
|
if latest is not None:
|
||||||
next = increment(latest)
|
next_serial = increment(latest)
|
||||||
|
|
||||||
if next != increment:
|
if next_serial != increment:
|
||||||
data['next'] = next
|
data['next'] = next_serial
|
||||||
|
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
|
@ -1530,15 +1530,15 @@ class Part(MPTTModel):
|
|||||||
returns a string representation of a hash object which can be compared with a stored value
|
returns a string representation of a hash object which can be compared with a stored value
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hash = hashlib.md5(str(self.id).encode())
|
result_hash = hashlib.md5(str(self.id).encode())
|
||||||
|
|
||||||
# List *all* BOM items (including inherited ones!)
|
# List *all* BOM items (including inherited ones!)
|
||||||
bom_items = self.get_bom_items().all().prefetch_related('sub_part')
|
bom_items = self.get_bom_items().all().prefetch_related('sub_part')
|
||||||
|
|
||||||
for item in bom_items:
|
for item in bom_items:
|
||||||
hash.update(str(item.get_item_hash()).encode())
|
result_hash.update(str(item.get_item_hash()).encode())
|
||||||
|
|
||||||
return str(hash.digest())
|
return str(result_hash.digest())
|
||||||
|
|
||||||
def is_bom_valid(self):
|
def is_bom_valid(self):
|
||||||
""" Check if the BOM is 'valid' - if the calculated checksum matches the stored value
|
""" Check if the BOM is 'valid' - if the calculated checksum matches the stored value
|
||||||
@ -2676,18 +2676,18 @@ class BomItem(models.Model):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Seed the hash with the ID of this BOM item
|
# Seed the hash with the ID of this BOM item
|
||||||
hash = hashlib.md5(str(self.id).encode())
|
result_hash = hashlib.md5(str(self.id).encode())
|
||||||
|
|
||||||
# Update the hash based on line information
|
# Update the hash based on line information
|
||||||
hash.update(str(self.sub_part.id).encode())
|
result_hash.update(str(self.sub_part.id).encode())
|
||||||
hash.update(str(self.sub_part.full_name).encode())
|
result_hash.update(str(self.sub_part.full_name).encode())
|
||||||
hash.update(str(self.quantity).encode())
|
result_hash.update(str(self.quantity).encode())
|
||||||
hash.update(str(self.note).encode())
|
result_hash.update(str(self.note).encode())
|
||||||
hash.update(str(self.reference).encode())
|
result_hash.update(str(self.reference).encode())
|
||||||
hash.update(str(self.optional).encode())
|
result_hash.update(str(self.optional).encode())
|
||||||
hash.update(str(self.inherited).encode())
|
result_hash.update(str(self.inherited).encode())
|
||||||
|
|
||||||
return str(hash.digest())
|
return str(result_hash.digest())
|
||||||
|
|
||||||
def validate_hash(self, valid=True):
|
def validate_hash(self, valid=True):
|
||||||
""" Mark this item as 'valid' (store the checksum hash).
|
""" Mark this item as 'valid' (store the checksum hash).
|
||||||
|
@ -293,7 +293,7 @@ def progress_bar(val, max, *args, **kwargs):
|
|||||||
Render a progress bar element
|
Render a progress bar element
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id = kwargs.get('id', 'progress-bar')
|
item_id = kwargs.get('id', 'progress-bar')
|
||||||
|
|
||||||
if val > max:
|
if val > max:
|
||||||
style = 'progress-bar-over'
|
style = 'progress-bar-over'
|
||||||
@ -317,7 +317,7 @@ def progress_bar(val, max, *args, **kwargs):
|
|||||||
style_tags.append(f'max-width: {max_width};')
|
style_tags.append(f'max-width: {max_width};')
|
||||||
|
|
||||||
html = f"""
|
html = f"""
|
||||||
<div id='{id}' class='progress' style='{" ".join(style_tags)}'>
|
<div id='{item_id}' class='progress' style='{" ".join(style_tags)}'>
|
||||||
<div class='progress-bar {style}' role='progressbar' aria-valuemin='0' aria-valuemax='100' style='width:{percent}%'></div>
|
<div class='progress-bar {style}' role='progressbar' aria-valuemin='0' aria-valuemax='100' style='width:{percent}%'></div>
|
||||||
<div class='progress-value'>{val} / {max}</div>
|
<div class='progress-value'>{val} / {max}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -30,8 +30,8 @@ class TemplateTagTest(TestCase):
|
|||||||
self.assertEqual(type(inventree_extras.inventree_version()), str)
|
self.assertEqual(type(inventree_extras.inventree_version()), str)
|
||||||
|
|
||||||
def test_hash(self):
|
def test_hash(self):
|
||||||
hash = inventree_extras.inventree_commit_hash()
|
result_hash = inventree_extras.inventree_commit_hash()
|
||||||
self.assertGreater(len(hash), 5)
|
self.assertGreater(len(result_hash), 5)
|
||||||
|
|
||||||
def test_date(self):
|
def test_date(self):
|
||||||
d = inventree_extras.inventree_commit_date()
|
d = inventree_extras.inventree_commit_date()
|
||||||
|
@ -173,8 +173,8 @@ class IntegrationPluginBase(MixinBase, plugin_base.InvenTreePluginBase):
|
|||||||
"""
|
"""
|
||||||
License of plugin
|
License of plugin
|
||||||
"""
|
"""
|
||||||
license = getattr(self, 'LICENSE', None)
|
lic = getattr(self, 'LICENSE', None)
|
||||||
return license
|
return lic
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user