2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Catch edge case for merge_stock_items: (#7373)

* Catch edge case for merge_stock_items:

- Use current location as backup
- Handle null location

* Fix deltas
This commit is contained in:
Oliver 2024-05-30 20:03:16 +10:00 committed by GitHub
parent 798c0ed322
commit 9fa2735f7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1695,6 +1695,9 @@ class StockItem(
- Tracking history for the *other* item is deleted - Tracking history for the *other* item is deleted
- Any allocations (build order, sales order) are moved to this StockItem - Any allocations (build order, sales order) are moved to this StockItem
""" """
if isinstance(other_items, StockItem):
other_items = [other_items]
if len(other_items) == 0: if len(other_items) == 0:
return return
@ -1702,7 +1705,7 @@ class StockItem(
tree_ids = {self.tree_id} tree_ids = {self.tree_id}
user = kwargs.get('user', None) user = kwargs.get('user', None)
location = kwargs.get('location', None) location = kwargs.get('location', self.location)
notes = kwargs.get('notes', None) notes = kwargs.get('notes', None)
parent_id = self.parent.pk if self.parent else None parent_id = self.parent.pk if self.parent else None
@ -1710,6 +1713,9 @@ class StockItem(
for other in other_items: for other in other_items:
# If the stock item cannot be merged, return # If the stock item cannot be merged, return
if not self.can_merge(other, raise_error=raise_error, **kwargs): if not self.can_merge(other, raise_error=raise_error, **kwargs):
logger.warning(
'Stock item <%s> could not be merge into <%s>', other.pk, self.pk
)
return return
tree_ids.add(other.tree_id) tree_ids.add(other.tree_id)
@ -1739,7 +1745,7 @@ class StockItem(
user, user,
quantity=self.quantity, quantity=self.quantity,
notes=notes, notes=notes,
deltas={'location': location.pk}, deltas={'location': location.pk if location else None},
) )
self.location = location self.location = location