diff --git a/src/backend/InvenTree/stock/models.py b/src/backend/InvenTree/stock/models.py index 1b9cfa8905cc..1def243c1a60 100644 --- a/src/backend/InvenTree/stock/models.py +++ b/src/backend/InvenTree/stock/models.py @@ -1695,6 +1695,9 @@ 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 @@ -1702,7 +1705,7 @@ def merge_stock_items(self, other_items, raise_error=False, **kwargs): 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 @@ -1710,6 +1713,9 @@ def merge_stock_items(self, other_items, raise_error=False, **kwargs): 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) @@ -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