2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 03:26:45 +00:00

Ensure that stock item trees are rebuilt correctly after serialization (#8193)

- No idea how this has not been detected previously
This commit is contained in:
Oliver 2024-09-26 22:54:45 +10:00 committed by GitHub
parent 83be3cfa71
commit b12bd3bb4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1577,6 +1577,13 @@ class StockItem(
# Remove the equivalent number of items
self.take_stock(quantity, user, notes=notes)
# Rebuild the stock tree
try:
StockItem.objects.partial_rebuild(tree_id=self.tree_id)
except Exception:
logger.warning('Failed to rebuild stock tree during serializeStock')
StockItem.objects.rebuild()
@transaction.atomic
def copyHistoryFrom(self, other):
"""Copy stock history from another StockItem."""
@ -1811,7 +1818,7 @@ class StockItem(
for tree_id in tree_ids:
StockItem.objects.partial_rebuild(tree_id=tree_id)
except Exception:
logger.warning('Rebuilding entire StockItem tree')
logger.warning('Rebuilding entire StockItem tree during merge_stock_items')
StockItem.objects.rebuild()
@transaction.atomic