mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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:
parent
e7317522a6
commit
c45e66935a
@ -267,6 +267,7 @@ class StockHistoryCode(StatusCode):
|
||||
|
||||
# Location operations
|
||||
STOCK_MOVE = 20
|
||||
STOCK_UPDATE = 25
|
||||
|
||||
# Installation operations
|
||||
INSTALLED_INTO_ASSEMBLY = 30
|
||||
@ -316,6 +317,7 @@ class StockHistoryCode(StatusCode):
|
||||
STOCK_REMOVE: _('Stock manually removed'),
|
||||
|
||||
STOCK_MOVE: _('Location changed'),
|
||||
STOCK_UPDATE: _('Stock updated'),
|
||||
|
||||
INSTALLED_INTO_ASSEMBLY: _('Installed into assembly'),
|
||||
REMOVED_FROM_ASSEMBLY: _('Removed from assembly'),
|
||||
|
@ -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()
|
||||
|
@ -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."""
|
||||
|
@ -2648,13 +2648,13 @@ function loadStockTrackingTable(table, options) {
|
||||
field: 'deltas',
|
||||
title: '{% trans "Details" %}',
|
||||
formatter: function(details, row) {
|
||||
var html = `<table class='table table-condensed' id='tracking-table-${row.pk}'>`;
|
||||
|
||||
if (!details) {
|
||||
html += '</table>';
|
||||
return html;
|
||||
if (!details || !Object.keys(details).length) {
|
||||
return `<small><em>{% trans "No changes" %}</em></small>`;
|
||||
}
|
||||
|
||||
let html = `<table class='table table-condensed' id='tracking-table-${row.pk}'>`;
|
||||
|
||||
// Part information
|
||||
if (details.part) {
|
||||
html += `<tr><th>{% trans "Part" %}</th><td>`;
|
||||
|
Loading…
Reference in New Issue
Block a user