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.show_snackbar(text, bgcolor='yellow')
|
||||||
self.page.update()
|
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):
|
def open_ring_click(self, e):
|
||||||
value = self.main_input.value or None
|
value = self.main_input.value or None
|
||||||
if not value:
|
if not value:
|
||||||
|
@ -1049,10 +1062,8 @@ class POSView(WuttaView):
|
||||||
self.reset()
|
self.reset()
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
amount = self.require_decimal(value)
|
||||||
amount = decimal.Decimal(value)
|
if amount is False:
|
||||||
except decimal.InvalidOperation:
|
|
||||||
self.show_snackbar("Amount is not valid")
|
|
||||||
self.reset()
|
self.reset()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1131,16 +1142,14 @@ class POSView(WuttaView):
|
||||||
self.page.update()
|
self.page.update()
|
||||||
|
|
||||||
def confirm(e):
|
def confirm(e):
|
||||||
dlg.open = False
|
price = self.require_decimal(price_override.value)
|
||||||
|
if price is False:
|
||||||
try:
|
|
||||||
price = decimal.Decimal(price_override.value)
|
|
||||||
except decimal.InvalidOperation:
|
|
||||||
self.show_snackbar(f"Price is not valid: {price_override.value}", bgcolor='yellow')
|
|
||||||
self.main_input.focus()
|
self.main_input.focus()
|
||||||
self.page.update()
|
self.page.update()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
dlg.open = False
|
||||||
|
|
||||||
session = self.app.make_session()
|
session = self.app.make_session()
|
||||||
user = self.get_current_user(session)
|
user = self.get_current_user(session)
|
||||||
handler = self.get_batch_handler()
|
handler = self.get_batch_handler()
|
||||||
|
@ -1507,12 +1516,9 @@ class POSView(WuttaView):
|
||||||
return
|
return
|
||||||
|
|
||||||
# nothing to do if amount not valid
|
# nothing to do if amount not valid
|
||||||
try:
|
amount = self.require_decimal(self.main_input.value)
|
||||||
amount = decimal.Decimal(self.main_input.value)
|
if amount is False:
|
||||||
except:
|
|
||||||
session.close()
|
session.close()
|
||||||
self.show_snackbar(f"AMOUNT NOT VALID: {self.main_input.value}",
|
|
||||||
bgcolor='yellow')
|
|
||||||
self.reset()
|
self.reset()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue