2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Stock transfer same location (#4757)

* Allow stock items to be transferred into the same location

* Add new code when moving into same location

* Update unit test

* Further unit test fixes
This commit is contained in:
Oliver
2023-05-05 12:55:31 +10:00
committed by GitHub
parent e7317522a6
commit c45e66935a
4 changed files with 20 additions and 13 deletions

View File

@ -1665,9 +1665,6 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
if location is None:
# TODO - Raise appropriate error (cannot move to blank location)
return False
elif self.location and (location.pk == self.location.pk) and (quantity == self.quantity):
# TODO - Raise appropriate error (cannot move to same location)
return False
# Test for a partial movement
if quantity < self.quantity:
@ -1678,16 +1675,25 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
return True
# Moving into the same location triggers a different history code
same_location = location == self.location
self.location = location
tracking_info = {}
tracking_code = StockHistoryCode.STOCK_MOVE
if same_location:
tracking_code = StockHistoryCode.STOCK_UPDATE
else:
tracking_info['location'] = location.pk
self.add_tracking_entry(
StockHistoryCode.STOCK_MOVE,
tracking_code,
user,
notes=notes,
deltas=tracking_info,
location=location,
)
self.save()

View File

@ -376,15 +376,14 @@ class StockTest(StockTestBase):
self.assertEqual(track.notes, 'Moved to the bathroom')
def test_self_move(self):
"""Test moving stock to itself does not work."""
# Try to move an item to its current location (should fail)
"""Test moving stock to its current location."""
it = StockItem.objects.get(pk=1)
n = it.tracking_info.count()
self.assertFalse(it.move(it.location, 'Moved to same place', None))
self.assertTrue(it.move(it.location, 'Moved to same place', None))
# Ensure tracking info was not added
self.assertEqual(it.tracking_info.count(), n)
self.assertEqual(it.tracking_info.count(), n + 1)
def test_partial_move(self):
"""Test partial stock moving."""