mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-05 13:10:57 +00:00
Update data migration file (#4596)
* Update data migration file - Do not call "save()" on the ORM model as it has some other hooks - Manually calculate checksum to determine which line items are "valid" - Update BomItem checksum calculation * Update BomItem hashing function - Ensure it remains the same after saving - Must use normalize(quantity) otherwise weird issues
This commit is contained in:
@ -3631,32 +3631,32 @@ class BomItem(DataImportMixin, MetadataMixin, models.Model):
|
||||
"""Calculate the checksum hash of this BOM line item.
|
||||
|
||||
The hash is calculated from the following fields:
|
||||
- Part.full_name (if the part name changes, the BOM checksum is invalidated)
|
||||
- Quantity
|
||||
- Reference field
|
||||
- Note field
|
||||
- Optional field
|
||||
- Inherited field
|
||||
- part.pk
|
||||
- sub_part.pk
|
||||
- quantity
|
||||
- reference
|
||||
- optional
|
||||
- inherited
|
||||
- consumable
|
||||
- allow_variants
|
||||
"""
|
||||
# Seed the hash with the ID of this BOM item
|
||||
result_hash = hashlib.md5(str(self.id).encode())
|
||||
result_hash = hashlib.md5(''.encode())
|
||||
|
||||
# Update the hash based on line information
|
||||
result_hash.update(str(self.sub_part.id).encode())
|
||||
result_hash.update(str(self.sub_part.full_name).encode())
|
||||
result_hash.update(str(self.quantity).encode())
|
||||
result_hash.update(str(self.note).encode())
|
||||
result_hash.update(str(self.reference).encode())
|
||||
result_hash.update(str(self.optional).encode())
|
||||
result_hash.update(str(self.inherited).encode())
|
||||
# The following components are used to calculate the checksum
|
||||
components = [
|
||||
self.part.pk,
|
||||
self.sub_part.pk,
|
||||
normalize(self.quantity),
|
||||
self.reference,
|
||||
self.optional,
|
||||
self.inherited,
|
||||
self.consumable,
|
||||
self.allow_variants
|
||||
]
|
||||
|
||||
# Optionally encoded for backwards compatibility
|
||||
if self.consumable:
|
||||
result_hash.update(str(self.consumable).encode())
|
||||
|
||||
# Optionally encoded for backwards compatibility
|
||||
if self.allow_variants:
|
||||
result_hash.update(str(self.allow_variants).encode())
|
||||
for component in components:
|
||||
result_hash.update(str(component).encode())
|
||||
|
||||
return str(result_hash.digest())
|
||||
|
||||
@ -3667,7 +3667,7 @@ class BomItem(DataImportMixin, MetadataMixin, models.Model):
|
||||
valid: If true, validate the hash, otherwise invalidate it (default = True)
|
||||
"""
|
||||
if valid:
|
||||
self.checksum = str(self.get_item_hash())
|
||||
self.checksum = self.get_item_hash()
|
||||
else:
|
||||
self.checksum = ''
|
||||
|
||||
|
Reference in New Issue
Block a user