Commit 1f19224f authored by anthraxx's avatar anthraxx
Browse files

implemented option to allow or reject unknown ids

parent d8434d33
......@@ -17,6 +17,7 @@ class FooBarPay:
DEFAULT_SCANNER = '/dev/input/by-id/usb-©_Symbol_Technologies__Inc__2000_Symbol_Bar_Code_Scanner_S_N:ac08a7010000_Rev:NBRXUAAQ3-event-kbd'
DEFAULT_DISPLAY = '/dev/hidraw1'
DEFAULT_DATABASE = 'sqlite:///foobarpay.sqlite'
ALLOW_CUSTOMER_CREATION = False
def __init__(self, cli_arguments):
logging.basicConfig(level=logging.DEBUG if cli_arguments.debug else logging.INFO)
......@@ -31,7 +32,7 @@ class FooBarPay:
else:
self.scanner = EvdevScanner(cli_arguments.scanner)
self.initialize_products()
self.logic = Logic(self.display, self.database)
self.logic = Logic(self.display, self.database, allow_customer_creation=self.ALLOW_CUSTOMER_CREATION)
def initialize_products(self):
self.database.get_or_create(Product, id=4100060009503, name="Extaler Mineralquell", price=100)
......
......@@ -13,9 +13,10 @@ class Logic(object):
USER_ID_PREFIX = '999'
LOAD_PREFIX = '980'
def __init__(self, display, database):
def __init__(self, display, database, allow_customer_creation=True):
self.display = display
self.database = database
self.allow_customer_creation = allow_customer_creation
self.reset()
def reset(self):
......@@ -27,7 +28,14 @@ class Logic(object):
def transaction_start(self, customer_id):
logging.info("Starting transaction")
self.customer = self.database.get_or_create(Customer, id=customer_id)
if self.allow_customer_creation:
self.customer = self.database.get_or_create(Customer, id=customer_id)
else:
self.customer = self.database.get(Customer, id=customer_id)
if self.customer is None:
logging.warn("Unknown customer id: {}".format(customer_id))
self.display.show_two_messages("Error", "Unknown id")
return
logging.debug("Name: {}".format(self.customer.name))
logging.debug("Saldo: {}".format(self.customer.saldo))
self.display.show_two_messages("Hello {}".format(self.customer.name), "S: {:+.2f}".format(self.customer.saldo/100))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment