2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-10 05:40:55 +00:00

Add API endpoint for validating a BOM item

This commit is contained in:
Oliver Walters
2019-09-05 19:29:51 +10:00
parent 81f5714cb1
commit 37d9c59a0e
3 changed files with 54 additions and 7 deletions

View File

@@ -1176,16 +1176,28 @@ class BomItem(models.Model):
return str(hash.digest())
def validate_hash(self):
""" Mark this item as 'valid' (store the checksum hash) """
def validate_hash(self, valid=True):
""" Mark this item as 'valid' (store the checksum hash).
Args:
valid: If true, validate the hash, otherwise invalidate it (default = True)
"""
if valid:
self.checksum = str(self.get_item_hash())
else:
self.checksum = ''
self.checksum = str(self.get_item_hash())
self.save()
@property
def is_line_valid(self):
""" Check if this line item has been validated by the user """
# Ensure an empty checksum returns False
if len(self.checksum) == 0:
return False
return self.get_item_hash() == self.checksum
def clean(self):