mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-03 11:28:49 +00:00
Merge branch 'master' into block-notes
This commit is contained in:
@@ -2663,7 +2663,7 @@ class StockItem(
|
||||
return True
|
||||
|
||||
@transaction.atomic
|
||||
def stocktake(self, count, user, **kwargs):
|
||||
def stocktake(self, count, user, **kwargs) -> None:
|
||||
"""Perform item stocktake.
|
||||
|
||||
Arguments:
|
||||
@@ -2678,7 +2678,7 @@ class StockItem(
|
||||
try:
|
||||
count = Decimal(count)
|
||||
except InvalidOperation:
|
||||
return False
|
||||
return
|
||||
|
||||
if count < 0:
|
||||
return False
|
||||
@@ -2706,8 +2706,8 @@ class StockItem(
|
||||
)
|
||||
tracking_info['old_status_logical'] = old_status_logical
|
||||
|
||||
if self.updateQuantity(count):
|
||||
tracking_info['quantity'] = float(count)
|
||||
if self.serialized or self.updateQuantity(count):
|
||||
tracking_info['quantity'] = 1 if self.serialized else float(count)
|
||||
|
||||
self.stocktake_date = InvenTree.helpers.current_date()
|
||||
self.stocktake_user = user
|
||||
@@ -2727,14 +2727,11 @@ class StockItem(
|
||||
deltas=tracking_info,
|
||||
)
|
||||
|
||||
trigger_event(
|
||||
StockEvents.ITEM_COUNTED,
|
||||
'stockitem.counted',
|
||||
id=self.id,
|
||||
quantity=float(self.quantity),
|
||||
)
|
||||
|
||||
return True
|
||||
trigger_event(
|
||||
StockEvents.ITEM_COUNTED,
|
||||
id=self.id,
|
||||
quantity=1 if self.serialized else float(self.quantity),
|
||||
)
|
||||
|
||||
@transaction.atomic
|
||||
def add_stock(self, quantity, user, **kwargs):
|
||||
|
||||
@@ -2289,6 +2289,32 @@ class StocktakeTest(StockAPITestCase):
|
||||
self.assertEqual(response.data['items'][0]['pk'], 1234)
|
||||
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):
|
||||
"""Test stock transfers."""
|
||||
stock_item = StockItem.objects.get(pk=1234)
|
||||
|
||||
@@ -378,10 +378,8 @@ class StockTest(StockTestBase):
|
||||
self.assertEqual(it.status, StockStatus.OK.value)
|
||||
|
||||
# Next, perform a valid stocktake
|
||||
self.assertTrue(
|
||||
it.stocktake(
|
||||
100, None, notes='test stocktake', status=StockStatus.DAMAGED.value
|
||||
)
|
||||
it.stocktake(
|
||||
100, None, notes='test stocktake', status=StockStatus.DAMAGED.value
|
||||
)
|
||||
|
||||
it.refresh_from_db()
|
||||
|
||||
Reference in New Issue
Block a user