Require decimal point when user enters currency amount
e.g. '10.' or '.10' is ok, but '10' is not allowed due to ambiguity
This commit is contained in:
parent
7edceac934
commit
4a9c93c96b
|
@ -1042,6 +1042,19 @@ class POSView(WuttaView):
|
|||
self.show_snackbar(text, bgcolor='yellow')
|
||||
self.page.update()
|
||||
|
||||
def require_decimal(self, value):
|
||||
try:
|
||||
amount = decimal.Decimal(value)
|
||||
except decimal.InvalidOperation:
|
||||
self.show_snackbar(f"Amount is not valid: {value}", bgcolor='yellow')
|
||||
return False
|
||||
|
||||
if '.' not in value:
|
||||
self.show_snackbar(f"Decimal point required: {value}", bgcolor='yellow')
|
||||
return False
|
||||
|
||||
return amount
|
||||
|
||||
def open_ring_click(self, e):
|
||||
value = self.main_input.value or None
|
||||
if not value:
|
||||
|
@ -1049,10 +1062,8 @@ class POSView(WuttaView):
|
|||
self.reset()
|
||||
return
|
||||
|
||||
try:
|
||||
amount = decimal.Decimal(value)
|
||||
except decimal.InvalidOperation:
|
||||
self.show_snackbar("Amount is not valid")
|
||||
amount = self.require_decimal(value)
|
||||
if amount is False:
|
||||
self.reset()
|
||||
return
|
||||
|
||||
|
@ -1131,16 +1142,14 @@ class POSView(WuttaView):
|
|||
self.page.update()
|
||||
|
||||
def confirm(e):
|
||||
dlg.open = False
|
||||
|
||||
try:
|
||||
price = decimal.Decimal(price_override.value)
|
||||
except decimal.InvalidOperation:
|
||||
self.show_snackbar(f"Price is not valid: {price_override.value}", bgcolor='yellow')
|
||||
price = self.require_decimal(price_override.value)
|
||||
if price is False:
|
||||
self.main_input.focus()
|
||||
self.page.update()
|
||||
return
|
||||
|
||||
dlg.open = False
|
||||
|
||||
session = self.app.make_session()
|
||||
user = self.get_current_user(session)
|
||||
handler = self.get_batch_handler()
|
||||
|
@ -1507,12 +1516,9 @@ class POSView(WuttaView):
|
|||
return
|
||||
|
||||
# nothing to do if amount not valid
|
||||
try:
|
||||
amount = decimal.Decimal(self.main_input.value)
|
||||
except:
|
||||
amount = self.require_decimal(self.main_input.value)
|
||||
if amount is False:
|
||||
session.close()
|
||||
self.show_snackbar(f"AMOUNT NOT VALID: {self.main_input.value}",
|
||||
bgcolor='yellow')
|
||||
self.reset()
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in a new issue