Skip to content

Commit

Permalink
Catch edge case for merge_stock_items: (#7373)
Browse files Browse the repository at this point in the history
* Catch edge case for merge_stock_items:

- Use current location as backup
- Handle null location

* Fix deltas
  • Loading branch information
SchrodingersGat authored May 30, 2024
1 parent 798c0ed commit 9fa2735
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/backend/InvenTree/stock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1695,21 +1695,27 @@ def merge_stock_items(self, other_items, raise_error=False, **kwargs):
- Tracking history for the *other* item is deleted
- 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:
return

# Keep track of the tree IDs that are being merged
tree_ids = {self.tree_id}

user = kwargs.get('user', None)
location = kwargs.get('location', None)
location = kwargs.get('location', self.location)
notes = kwargs.get('notes', None)

parent_id = self.parent.pk if self.parent else None

for other in other_items:
# If the stock item cannot be merged, return
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

tree_ids.add(other.tree_id)
Expand Down Expand Up @@ -1739,7 +1745,7 @@ def merge_stock_items(self, other_items, raise_error=False, **kwargs):
user,
quantity=self.quantity,
notes=notes,
deltas={'location': location.pk},
deltas={'location': location.pk if location else None},
)

self.location = location
Expand Down

0 comments on commit 9fa2735

Please sign in to comment.