mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Fixes for unit tests
This commit is contained in:
		| @@ -121,12 +121,17 @@ class StockAdjust(APIView): | |||||||
|     - StockAdd: add stock items |     - StockAdd: add stock items | ||||||
|     - StockRemove: remove stock items |     - StockRemove: remove stock items | ||||||
|     - StockTransfer: transfer stock items |     - StockTransfer: transfer stock items | ||||||
|  |  | ||||||
|  |     # TODO - This needs serious refactoring!!! | ||||||
|  |  | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|     permission_classes = [ |     permission_classes = [ | ||||||
|         permissions.IsAuthenticated, |         permissions.IsAuthenticated, | ||||||
|     ] |     ] | ||||||
|  |  | ||||||
|  |     allow_missing_quantity = False | ||||||
|  |  | ||||||
|     def get_items(self, request): |     def get_items(self, request): | ||||||
|         """ |         """ | ||||||
|         Return a list of items posted to the endpoint. |         Return a list of items posted to the endpoint. | ||||||
| @@ -157,11 +162,13 @@ class StockAdjust(APIView): | |||||||
|             except (ValueError, StockItem.DoesNotExist): |             except (ValueError, StockItem.DoesNotExist): | ||||||
|                 raise ValidationError({'pk': 'Each entry must contain a valid pk field'}) |                 raise ValidationError({'pk': 'Each entry must contain a valid pk field'}) | ||||||
|  |  | ||||||
|  |             if self.allow_missing_quantity and 'quantity' not in entry: | ||||||
|  |                 entry['quantity'] = item.quantity | ||||||
|  |  | ||||||
|             try: |             try: | ||||||
|                 quantity = Decimal(str(entry.get('quantity', None))) |                 quantity = Decimal(str(entry.get('quantity', None))) | ||||||
|             except (ValueError, TypeError, InvalidOperation): |             except (ValueError, TypeError, InvalidOperation): | ||||||
|                 # Default to the quantity of the item |                 raise ValidationError({'quantity': "Each entry must contain a valid quantity value"}) | ||||||
|                 quantity = item.quantity |  | ||||||
|  |  | ||||||
|             if quantity < 0: |             if quantity < 0: | ||||||
|                 raise ValidationError({'quantity': 'Quantity field must not be less than zero'}) |                 raise ValidationError({'quantity': 'Quantity field must not be less than zero'}) | ||||||
| @@ -235,6 +242,8 @@ class StockTransfer(StockAdjust): | |||||||
|     API endpoint for performing stock movements |     API endpoint for performing stock movements | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|  |     allow_missing_quantity = True | ||||||
|  |  | ||||||
|     def post(self, request, *args, **kwargs): |     def post(self, request, *args, **kwargs): | ||||||
|  |  | ||||||
|         self.get_items(request) |         self.get_items(request) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user