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
|
# Location operations
|
||||||
STOCK_MOVE = 20
|
STOCK_MOVE = 20
|
||||||
|
STOCK_UPDATE = 25
|
||||||
|
|
||||||
# Installation operations
|
# Installation operations
|
||||||
INSTALLED_INTO_ASSEMBLY = 30
|
INSTALLED_INTO_ASSEMBLY = 30
|
||||||
@ -316,6 +317,7 @@ class StockHistoryCode(StatusCode):
|
|||||||
STOCK_REMOVE: _('Stock manually removed'),
|
STOCK_REMOVE: _('Stock manually removed'),
|
||||||
|
|
||||||
STOCK_MOVE: _('Location changed'),
|
STOCK_MOVE: _('Location changed'),
|
||||||
|
STOCK_UPDATE: _('Stock updated'),
|
||||||
|
|
||||||
INSTALLED_INTO_ASSEMBLY: _('Installed into assembly'),
|
INSTALLED_INTO_ASSEMBLY: _('Installed into assembly'),
|
||||||
REMOVED_FROM_ASSEMBLY: _('Removed from assembly'),
|
REMOVED_FROM_ASSEMBLY: _('Removed from assembly'),
|
||||||
|
@ -1665,9 +1665,6 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
|||||||
if location is None:
|
if location is None:
|
||||||
# TODO - Raise appropriate error (cannot move to blank location)
|
# TODO - Raise appropriate error (cannot move to blank location)
|
||||||
return False
|
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
|
# Test for a partial movement
|
||||||
if quantity < self.quantity:
|
if quantity < self.quantity:
|
||||||
@ -1678,16 +1675,25 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Moving into the same location triggers a different history code
|
||||||
|
same_location = location == self.location
|
||||||
|
|
||||||
self.location = location
|
self.location = location
|
||||||
|
|
||||||
tracking_info = {}
|
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(
|
self.add_tracking_entry(
|
||||||
StockHistoryCode.STOCK_MOVE,
|
tracking_code,
|
||||||
user,
|
user,
|
||||||
notes=notes,
|
notes=notes,
|
||||||
deltas=tracking_info,
|
deltas=tracking_info,
|
||||||
location=location,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -376,15 +376,14 @@ class StockTest(StockTestBase):
|
|||||||
self.assertEqual(track.notes, 'Moved to the bathroom')
|
self.assertEqual(track.notes, 'Moved to the bathroom')
|
||||||
|
|
||||||
def test_self_move(self):
|
def test_self_move(self):
|
||||||
"""Test moving stock to itself does not work."""
|
"""Test moving stock to its current location."""
|
||||||
# Try to move an item to its current location (should fail)
|
|
||||||
it = StockItem.objects.get(pk=1)
|
it = StockItem.objects.get(pk=1)
|
||||||
|
|
||||||
n = it.tracking_info.count()
|
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
|
# 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):
|
def test_partial_move(self):
|
||||||
"""Test partial stock moving."""
|
"""Test partial stock moving."""
|
||||||
|
@ -2648,13 +2648,13 @@ function loadStockTrackingTable(table, options) {
|
|||||||
field: 'deltas',
|
field: 'deltas',
|
||||||
title: '{% trans "Details" %}',
|
title: '{% trans "Details" %}',
|
||||||
formatter: function(details, row) {
|
formatter: function(details, row) {
|
||||||
var html = `<table class='table table-condensed' id='tracking-table-${row.pk}'>`;
|
|
||||||
|
|
||||||
if (!details) {
|
if (!details || !Object.keys(details).length) {
|
||||||
html += '</table>';
|
return `<small><em>{% trans "No changes" %}</em></small>`;
|
||||||
return html;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let html = `<table class='table table-condensed' id='tracking-table-${row.pk}'>`;
|
||||||
|
|
||||||
// Part information
|
// Part information
|
||||||
if (details.part) {
|
if (details.part) {
|
||||||
html += `<tr><th>{% trans "Part" %}</th><td>`;
|
html += `<tr><th>{% trans "Part" %}</th><td>`;
|
||||||
|
Loading…
Reference in New Issue
Block a user