mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
clean_decimal should also check if the string can be converted to Decimal type
This commit is contained in:
parent
53f2aa107a
commit
456710c5ce
@ -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
|
||||
clean_number = Decimal(number)
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user