mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 04:56:45 +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
|
import os.path
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal, InvalidOperation
|
||||||
|
|
||||||
from wsgiref.util import FileWrapper
|
from wsgiref.util import FileWrapper
|
||||||
from django.http import StreamingHttpResponse
|
from django.http import StreamingHttpResponse
|
||||||
@ -655,6 +655,10 @@ def clean_decimal(number):
|
|||||||
number = number.replace(',', '')
|
number = number.replace(',', '')
|
||||||
|
|
||||||
# Convert to Decimal type
|
# 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()
|
return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user