def print_receipt(self, date): printer = maxatec.MaxatecPrinter(config.get('printer')) printer.text('Starfish Books', 'hwc') printer.text('*****@*****.**', 'c') printer.text('\n') printer.text('Receipt ID: ' + self.id) printer.text('Date: ' + date.ctime()) printer.text('\n') printer.line() for p in self.products: if p.qty > 1: printer.text('{0: <31}'.format(p.name)) printer.price(' {0} @ {1}'.format(p.qty, p.price), p.total()) else: printer.price(p.name, p.total()) printer.line() if self.discount: printer.price('Subtotal', self.total() + self.discount) printer.price('Discount', -self.discount) printer.price('Total', self.total(), 'h') printer.price('VAT', self.total_vat()) printer.text('\n') printer.text('Thank you.', 'c') printer.barcode(self.id, 'code39') printer.part_cut() printer.open_draw()
def populate(self): """Populates the widgets with the current configuration values.""" for name, value in DBTYPES: if value == config.get('database'): self.currentdb.set(name) self.input_dbuser.insert(0, config.get('dbuser')) self.input_dbpass.insert(0, config.get('dbpass')) self.input_dbhost.insert(0, config.get('dbhost')) self.input_dbname.insert(0, config.get('dbname')) self.input_id.insert(0, config.get('tillid')) self.input_name.insert(0, config.get('tillname'))
def load(): """ Connects to the database. Returns a tuple - the first element is one of the following strings if there is an error: 'connecterror' = Cannot connect. 'nodberror' = No database present. Otherwise a tuple ('success', Database, Store) is returned containing the 'till.lib.storm' object instances. """ type = config.get("database") user = config.get("dbuser") password = config.get("dbpass") host = config.get("dbhost") name = config.get("dbname") uri = type + "://" if user: uri += user if password: uri += ":" + password uri += "@" uri += host if name: uri += "/" uri += name database = create_database(uri) try: store = Store(database) except Exception: return ("connecterror",) try: result = store.execute("SELECT * FROM products") except Exception: return "nodberror", database, store return "success", database, store
def create_widgets(self): top = self.winfo_toplevel() top.geometry('640x480') top.rowconfigure(0, weight=1) top.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1) self.columnconfigure(0, weight=1) self.label_title = Label(self, text='Starfish Till (%s)' % config.get('tillname'), font=(24,), background='white') self.label_title.grid(row=0, column=0, sticky=E+W) self.frame_main = Frame(self) self.frame_main.grid(row=1, column=0, sticky=N+S+E+W) self.frame_main.rowconfigure(0, weight=1) self.frame_main.columnconfigure(0, weight=1)
def install(database, store): """Installs the database.""" if "TILLFILES" in os.environ.keys(): database = config.get("database") if database == "mysql": sql_file = "database_mysql.sql" elif database == "sqlite": sql_file = "database_sqlite.sql" else: sql_file = "database.sql" sql = os.path.join(os.environ["TILLFILES"], sql_file) try: with open(sql, "r") as f: store.execute(f.read()) store.flush() store.commit() except Exception as e: raise e return "error", e return ("success",)
def __init__(self): self.id = '{0:0>3}-{1:0>6}'.format(config.get('tillid'), config.get('nextid')) config.set('nextid', int(config.get('nextid'))+1) self.products = [] self.discount = D('0.00')