Fixes for unit testing

This commit is contained in:
Oliver Walters 2021-05-11 21:22:54 +10:00
parent 0020e85397
commit a1203aa1e5
2 changed files with 13 additions and 12 deletions

View File

@ -207,7 +207,7 @@ class StockItem(MPTTModel):
user, user,
deltas=tracking_info, deltas=tracking_info,
location=self.location, location=self.location,
quantity=self.quantity, quantity=float(self.quantity),
) )
@property @property
@ -977,7 +977,7 @@ class StockItem(MPTTModel):
Args: Args:
quantity: Number of items to serialize (integer) quantity: Number of items to serialize (integer)
serials: List of serial numbers (list<int>) serials: List of serial numbers
user: User object associated with action user: User object associated with action
notes: Optional notes for tracking notes: Optional notes for tracking
location: If specified, serialized items will be placed in the given location location: If specified, serialized items will be placed in the given location
@ -1267,7 +1267,7 @@ class StockItem(MPTTModel):
user, user,
notes=notes, notes=notes,
deltas={ deltas={
'quantity': self.quantity, 'quantity': float(self.quantity),
} }
) )
@ -1300,8 +1300,8 @@ class StockItem(MPTTModel):
user, user,
notes=notes, notes=notes,
deltas={ deltas={
'added': quantity, 'added': float(quantity),
'quantity': self.quantity 'quantity': float(self.quantity),
} }
) )
@ -1332,8 +1332,8 @@ class StockItem(MPTTModel):
user, user,
notes=notes, notes=notes,
deltas={ deltas={
'removed': quantity, 'removed': float(quantity),
'quantity': self.quantity, 'quantity': float(self.quantity),
} }
) )

View File

@ -5,6 +5,8 @@ from django.core.exceptions import ValidationError
import datetime import datetime
from InvenTree.status_codes import StockHistoryCode
from .models import StockLocation, StockItem, StockItemTracking from .models import StockLocation, StockItem, StockItemTracking
from .models import StockItemTestResult from .models import StockItemTestResult
@ -217,7 +219,7 @@ class StockTest(TestCase):
track = StockItemTracking.objects.filter(item=it).latest('id') track = StockItemTracking.objects.filter(item=it).latest('id')
self.assertEqual(track.item, it) self.assertEqual(track.item, it)
self.assertIn('Moved to', track.title) self.assertEqual(track.tracking_type, StockHistoryCode.STOCK_MOVE)
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):
@ -284,8 +286,7 @@ class StockTest(TestCase):
# Check that a tracking item was added # Check that a tracking item was added
track = StockItemTracking.objects.filter(item=it).latest('id') track = StockItemTracking.objects.filter(item=it).latest('id')
self.assertIn('Counted', track.title) self.assertEqual(track.tracking_type, StockHistoryCode.STOCK_COUNT)
self.assertIn('items', track.title)
self.assertIn('Counted items', track.notes) self.assertIn('Counted items', track.notes)
n = it.tracking_info.count() n = it.tracking_info.count()
@ -304,7 +305,7 @@ class StockTest(TestCase):
# Check that a tracking item was added # Check that a tracking item was added
track = StockItemTracking.objects.filter(item=it).latest('id') track = StockItemTracking.objects.filter(item=it).latest('id')
self.assertIn('Added', track.title) self.assertEqual(track.tracking_type, StockHistoryCode.STOCK_ADD)
self.assertIn('Added some items', track.notes) self.assertIn('Added some items', track.notes)
self.assertFalse(it.add_stock(-10, None)) self.assertFalse(it.add_stock(-10, None))
@ -319,7 +320,7 @@ class StockTest(TestCase):
# Check that a tracking item was added # Check that a tracking item was added
track = StockItemTracking.objects.filter(item=it).latest('id') track = StockItemTracking.objects.filter(item=it).latest('id')
self.assertIn('Removed', track.title) self.assertEqual(track.tracking_type, StockHistoryCode.STOCK_REMOVE)
self.assertIn('Removed some items', track.notes) self.assertIn('Removed some items', track.notes)
self.assertTrue(it.has_tracking_info) self.assertTrue(it.has_tracking_info)