reworked history logic

This commit is contained in:
Neil Beukes 2026-05-27 13:37:14 +00:00
parent 47ed85e180
commit f261bf7390
3 changed files with 2 additions and 18 deletions

View File

@ -2180,7 +2180,7 @@ class StockItem(
return True
def find_merge_target(self, location):
"""Find an existing stock item at *location* that can absorb this item."""
"""Find an existing stock item at location that can absorb this item."""
if location is None:
return None
@ -2215,11 +2215,8 @@ class StockItem(
*This* stock item subsumes the other, which is essentially deleted:
- The quantity of this StockItem is increased
- Tracking history for the *other* item is copied to this item (unless copy_history=False)
- Tracking history for the *other* item is deleted
- Any allocations (build order, sales order) are moved to this StockItem
kwargs:
copy_history: If True (default), copy tracking from merged items. Set False for merge-on-transfer.
"""
if isinstance(other_items, StockItem):
other_items = [other_items]
@ -2233,7 +2230,6 @@ class StockItem(
user = kwargs.get('user')
location = kwargs.get('location', self.location)
notes = kwargs.get('notes') or ''
copy_history = kwargs.pop('copy_history', True)
parent_id = self.parent.pk if self.parent else None
@ -2278,9 +2274,6 @@ class StockItem(
self.parent = None
self.save()
if copy_history:
self.copyHistoryFrom(other)
if other.location:
location_note = _('Transferred from %(location)s') % {
'location': other.location.pathstring

View File

@ -1893,7 +1893,6 @@ class StockTransferSerializer(StockAdjustmentSerializer):
'location': location,
'notes': notes,
'user': request.user,
'copy_history': False,
**kwargs,
}

View File

@ -722,20 +722,12 @@ class StockTest(StockTestBase):
s2 = StockItem.objects.create(part=part, quantity=20)
s3 = StockItem.objects.create(part=part, quantity=30)
s2.add_tracking_entry(
StockHistoryCode.STOCK_UPDATE, None, notes='Merged away tracking'
)
tracking_before = s1.tracking_info.count()
self.assertEqual(part.stock_items.count(), 3)
s1.merge_stock_items([s2, s3])
self.assertEqual(part.stock_items.count(), 1)
s1.refresh_from_db()
self.assertEqual(s1.quantity, 60)
self.assertIsNone(s1.purchase_price)
self.assertTrue(s1.tracking_info.filter(notes='Merged away tracking').exists())
self.assertGreater(s1.tracking_info.count(), tracking_before)
merge_entry = s1.tracking_info.filter(
tracking_type=StockHistoryCode.MERGED_STOCK_ITEMS