mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Fix tests for stock serialization
This commit is contained in:
		| @@ -67,7 +67,7 @@ class SerializeStockForm(forms.ModelForm): | |||||||
|     """ Form for serializing a StockItem. """ |     """ Form for serializing a StockItem. """ | ||||||
|  |  | ||||||
|     destination = forms.ChoiceField(label='Destination', required=True, help_text='Destination for serialized stock (by default, will remain in current location)') |     destination = forms.ChoiceField(label='Destination', required=True, help_text='Destination for serialized stock (by default, will remain in current location)') | ||||||
|     serial_numbers = forms.CharField(label='Serial numbers', required=True, help_text='Unique serial numbers (must match quantity)')     |     serial_numbers = forms.CharField(label='Serial numbers', required=True, help_text='Unique serial numbers (must match quantity)') | ||||||
|     note = forms.CharField(label='Notes', required=False, help_text='Add transaction note (optional)') |     note = forms.CharField(label='Notes', required=False, help_text='Add transaction note (optional)') | ||||||
|  |  | ||||||
|     def get_location_choices(self): |     def get_location_choices(self): | ||||||
|   | |||||||
| @@ -359,6 +359,7 @@ class StockItem(models.Model): | |||||||
|  |  | ||||||
|         Brief automated note detailing a movement or quantity change. |         Brief automated note detailing a movement or quantity change. | ||||||
|         """ |         """ | ||||||
|  |          | ||||||
|         track = StockItemTracking.objects.create( |         track = StockItemTracking.objects.create( | ||||||
|             item=self, |             item=self, | ||||||
|             title=title, |             title=title, | ||||||
| @@ -373,7 +374,7 @@ class StockItem(models.Model): | |||||||
|         track.save() |         track.save() | ||||||
|  |  | ||||||
|     @transaction.atomic |     @transaction.atomic | ||||||
|     def serializeStock(self, quantity, serials, user, notes=None, location=None): |     def serializeStock(self, quantity, serials, user, notes='', location=None): | ||||||
|         """ Split this stock item into unique serial numbers. |         """ Split this stock item into unique serial numbers. | ||||||
|  |  | ||||||
|         - Quantity can be less than or equal to the quantity of the stock item |         - Quantity can be less than or equal to the quantity of the stock item | ||||||
|   | |||||||
| @@ -264,24 +264,24 @@ class StockTest(TestCase): | |||||||
|         # Test serialization of non-serializable part |         # Test serialization of non-serializable part | ||||||
|         item = StockItem.objects.get(pk=1234) |         item = StockItem.objects.get(pk=1234) | ||||||
|  |  | ||||||
|         with self.assertRaises(ValueError): |         with self.assertRaises(ValidationError): | ||||||
|             item.serializeStock(5, [1, 2, 3, 4, 5], self.user) |             item.serializeStock(5, [1, 2, 3, 4, 5], self.user) | ||||||
|  |  | ||||||
|         # Pick a StockItem which can actually be serialized |         # Pick a StockItem which can actually be serialized | ||||||
|         item = StockItem.objects.get(pk=100) |         item = StockItem.objects.get(pk=100) | ||||||
|  |  | ||||||
|         # Try an invalid quantity |         # Try an invalid quantity | ||||||
|         with self.assertRaises(ValueError): |         with self.assertRaises(ValidationError): | ||||||
|             item.serializeStock("k", [], self.user) |             item.serializeStock("k", [], self.user) | ||||||
|  |  | ||||||
|         with self.assertRaises(ValueError): |         with self.assertRaises(ValidationError): | ||||||
|             item.serializeStock(-1, [], self.user) |             item.serializeStock(-1, [], self.user) | ||||||
|  |  | ||||||
|         # Try invalid serial numbers |         # Try invalid serial numbers | ||||||
|         with self.assertRaises(ValueError): |         with self.assertRaises(ValidationError): | ||||||
|             item.serializeStock(3, [1, 2, 'k'], self.user) |             item.serializeStock(3, [1, 2, 'k'], self.user) | ||||||
|  |  | ||||||
|         with self.assertRaises(ValueError): |         with self.assertRaises(ValidationError): | ||||||
|             item.serializeStock(3, "hello", self.user) |             item.serializeStock(3, "hello", self.user) | ||||||
|  |  | ||||||
|     def test_seiralize_stock_valid(self): |     def test_seiralize_stock_valid(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user