fix: allow comma in numeric filter input

just remove them and run with the remainder, on the SQL side
This commit is contained in:
Lance Edgar 2024-06-30 11:44:33 -05:00
parent eff5341335
commit 1dc632174e

View file

@ -26,6 +26,7 @@ Grid Filters
import re
import datetime
import decimal
import logging
from collections import OrderedDict
@ -647,12 +648,22 @@ class AlchemyNumericFilter(AlchemyGridFilter):
# first just make sure it's somewhat numeric
try:
float(value)
except ValueError:
self.parse_decimal(value)
except decimal.InvalidOperation:
return True
return bool(value and len(str(value)) > 8)
def parse_decimal(self, value):
if value:
value = value.replace(',', '')
return decimal.Decimal(value)
def encode_value(self, value):
if value:
value = str(self.parse_decimal(value))
return super().encode_value(value)
def filter_equal(self, query, value):
if self.value_invalid(value):
return query