mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-04 06:00:38 +00:00
* Fix stocktake bug for counting serialized items
* Add unit test
(cherry picked from commit 414aac0224)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
committed by
GitHub
parent
ffc60cb189
commit
9793bba77a
@@ -2651,8 +2651,8 @@ class StockItem(
|
|||||||
)
|
)
|
||||||
tracking_info['old_status_logical'] = old_status_logical
|
tracking_info['old_status_logical'] = old_status_logical
|
||||||
|
|
||||||
if self.updateQuantity(count):
|
if self.serialized or self.updateQuantity(count):
|
||||||
tracking_info['quantity'] = float(count)
|
tracking_info['quantity'] = 1 if self.serialized else float(count)
|
||||||
|
|
||||||
self.stocktake_date = InvenTree.helpers.current_date()
|
self.stocktake_date = InvenTree.helpers.current_date()
|
||||||
self.stocktake_user = user
|
self.stocktake_user = user
|
||||||
@@ -2672,12 +2672,12 @@ class StockItem(
|
|||||||
deltas=tracking_info,
|
deltas=tracking_info,
|
||||||
)
|
)
|
||||||
|
|
||||||
trigger_event(
|
trigger_event(
|
||||||
StockEvents.ITEM_COUNTED,
|
StockEvents.ITEM_COUNTED,
|
||||||
'stockitem.counted',
|
'stockitem.counted',
|
||||||
id=self.id,
|
id=self.id,
|
||||||
quantity=float(self.quantity),
|
quantity=1 if self.serialized else float(self.quantity),
|
||||||
)
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -2289,6 +2289,32 @@ class StocktakeTest(StockAPITestCase):
|
|||||||
self.assertEqual(response.data['items'][0]['pk'], 1234)
|
self.assertEqual(response.data['items'][0]['pk'], 1234)
|
||||||
self.assertEqual(response.data['items'][0]['quantity'], target[endpoint])
|
self.assertEqual(response.data['items'][0]['quantity'], target[endpoint])
|
||||||
|
|
||||||
|
def test_count_serialized(self):
|
||||||
|
"""Test that counting a serialized stock item correctly updates stocktake_date."""
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
# Fixture item pk=501 is a serialized item (serial=1)
|
||||||
|
item = StockItem.objects.get(pk=501)
|
||||||
|
self.assertTrue(item.serialized)
|
||||||
|
self.assertEqual(item.quantity, 1)
|
||||||
|
|
||||||
|
# Clear any existing stocktake date so we can verify it gets set
|
||||||
|
item.stocktake_date = None
|
||||||
|
item.save()
|
||||||
|
|
||||||
|
url = reverse('api-stock-count')
|
||||||
|
|
||||||
|
# Count the serialized item — quantity must be 1
|
||||||
|
data = {'items': [{'pk': item.pk, 'quantity': 1}]}
|
||||||
|
response = self.post(url, data, expected_code=201)
|
||||||
|
|
||||||
|
self.assertEqual(response.data['items'][0]['pk'], item.pk)
|
||||||
|
self.assertEqual(response.data['items'][0]['quantity'], '1.00000')
|
||||||
|
|
||||||
|
# stocktake_date must have been set to today
|
||||||
|
item.refresh_from_db()
|
||||||
|
self.assertEqual(item.stocktake_date, datetime.date.today())
|
||||||
|
|
||||||
def test_transfer(self):
|
def test_transfer(self):
|
||||||
"""Test stock transfers."""
|
"""Test stock transfers."""
|
||||||
stock_item = StockItem.objects.get(pk=1234)
|
stock_item = StockItem.objects.get(pk=1234)
|
||||||
|
|||||||
Reference in New Issue
Block a user