mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	clean_decimal should also check if the string can be converted to Decimal type
This commit is contained in:
		@@ -8,7 +8,7 @@ import json
 | 
			
		||||
import os.path
 | 
			
		||||
from PIL import Image
 | 
			
		||||
 | 
			
		||||
from decimal import Decimal
 | 
			
		||||
from decimal import Decimal, InvalidOperation
 | 
			
		||||
 | 
			
		||||
from wsgiref.util import FileWrapper
 | 
			
		||||
from django.http import StreamingHttpResponse
 | 
			
		||||
@@ -655,6 +655,10 @@ def clean_decimal(number):
 | 
			
		||||
            number = number.replace(',', '')
 | 
			
		||||
 | 
			
		||||
    # Convert to Decimal type
 | 
			
		||||
    try:
 | 
			
		||||
        clean_number = Decimal(number)
 | 
			
		||||
    except InvalidOperation:
 | 
			
		||||
        # Number cannot be converted to Decimal (eg. a string containing letters)
 | 
			
		||||
        return Decimal(0)
 | 
			
		||||
 | 
			
		||||
    return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user