Implement transaction printing.
This commit is contained in:
parent
2cf749fd6f
commit
71ba505c8b
|
@ -7,3 +7,7 @@ Path = pos.db
|
||||||
|
|
||||||
[FLASK]
|
[FLASK]
|
||||||
SECRET_KEY = CHANGE_ME_NOW!
|
SECRET_KEY = CHANGE_ME_NOW!
|
||||||
|
|
||||||
|
[PRINTER]
|
||||||
|
Host = 192.168.1.100
|
||||||
|
Post = 9100
|
||||||
|
|
|
@ -11,3 +11,7 @@ Password = secret
|
||||||
|
|
||||||
[FLASK]
|
[FLASK]
|
||||||
SECRET_KEY = CHANGE_ME_NOW!
|
SECRET_KEY = CHANGE_ME_NOW!
|
||||||
|
|
||||||
|
[PRINTER]
|
||||||
|
Host = 192.168.1.100
|
||||||
|
Post = 9100
|
||||||
|
|
|
@ -8,3 +8,4 @@ tabulate
|
||||||
PyYAML
|
PyYAML
|
||||||
flask>=0.12.0
|
flask>=0.12.0
|
||||||
flask_login>=0.4.0
|
flask_login>=0.4.0
|
||||||
|
python-escpos
|
||||||
|
|
BIN
static/img/macao-logo-printer.png
Normal file
BIN
static/img/macao-logo-printer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
52
web.py
52
web.py
|
@ -1,4 +1,6 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from time import sleep
|
||||||
|
import escpos.printer
|
||||||
|
|
||||||
from flask import Flask, redirect, request, render_template, flash
|
from flask import Flask, redirect, request, render_template, flash
|
||||||
from flask_login import LoginManager, login_user, logout_user, login_required
|
from flask_login import LoginManager, login_user, logout_user, login_required
|
||||||
|
@ -11,11 +13,20 @@ from pos.database import Database, User, Product, Event, Transaction, Order
|
||||||
config = Config()
|
config = Config()
|
||||||
debug = config.core['GENERAL'].getboolean('Debug', False)
|
debug = config.core['GENERAL'].getboolean('Debug', False)
|
||||||
conf_db = config.core['DATABASE']
|
conf_db = config.core['DATABASE']
|
||||||
|
conf_printer = config.core['PRINTER']
|
||||||
conf_flask = config.core['FLASK']
|
conf_flask = config.core['FLASK']
|
||||||
|
|
||||||
init_logging(config.logging)
|
init_logging(config.logging)
|
||||||
log = get_logger('web')
|
log = get_logger('web')
|
||||||
|
|
||||||
|
printer = escpos.printer.Network(
|
||||||
|
conf_printer['Host'],
|
||||||
|
port=conf_printer.getint('Port'),
|
||||||
|
timeout=15)
|
||||||
|
|
||||||
|
|
||||||
|
db = Database(**conf_db)
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.update(
|
app.config.update(
|
||||||
debug=debug,
|
debug=debug,
|
||||||
|
@ -27,8 +38,6 @@ login_manager.init_app(app)
|
||||||
login_manager.login_view = 'login'
|
login_manager.login_view = 'login'
|
||||||
login_manager.login_message_category = 'error'
|
login_manager.login_message_category = 'error'
|
||||||
|
|
||||||
db = Database(**conf_db)
|
|
||||||
|
|
||||||
|
|
||||||
@login_manager.user_loader
|
@login_manager.user_loader
|
||||||
def load_user(uid):
|
def load_user(uid):
|
||||||
|
@ -110,6 +119,43 @@ def sell_page():
|
||||||
title='Sell', event=event, products=products)
|
title='Sell', event=event, products=products)
|
||||||
|
|
||||||
|
|
||||||
|
def print_orders(event, orders):
|
||||||
|
printer.open()
|
||||||
|
|
||||||
|
printer.set(align='CENTER')
|
||||||
|
printer.image('static/img/macao-logo-printer.png', impl='bitImageColumn')
|
||||||
|
|
||||||
|
printer.set(align='CENTER', text_type='B')
|
||||||
|
printer.text(event.name.upper())
|
||||||
|
printer.text("\n\n")
|
||||||
|
|
||||||
|
for o in orders:
|
||||||
|
printer.set(align='LEFT', width=2, height=2)
|
||||||
|
printer.text("{} x {}".format(o.quantity, o.product.name.upper()))
|
||||||
|
printer.text("\n")
|
||||||
|
|
||||||
|
printer.text("\n")
|
||||||
|
|
||||||
|
printer.cut()
|
||||||
|
printer.close()
|
||||||
|
sleep(0.7)
|
||||||
|
|
||||||
|
|
||||||
|
def print_transaction(transaction):
|
||||||
|
categorized_orders = {}
|
||||||
|
|
||||||
|
for o in transaction.orders:
|
||||||
|
uid = o.product.category_uid
|
||||||
|
|
||||||
|
if not categorized_orders.get(uid, False):
|
||||||
|
categorized_orders[uid] = []
|
||||||
|
|
||||||
|
categorized_orders[uid].append(o)
|
||||||
|
|
||||||
|
for cat, orders in categorized_orders.items():
|
||||||
|
print_orders(transaction.event, orders)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/sell', methods=['POST'])
|
@app.route('/sell', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def sell():
|
def sell():
|
||||||
|
@ -135,6 +181,8 @@ def sell():
|
||||||
|
|
||||||
transaction = Transaction(event_uid=event.uid, orders=orders)
|
transaction = Transaction(event_uid=event.uid, orders=orders)
|
||||||
session.add(transaction)
|
session.add(transaction)
|
||||||
|
session.flush()
|
||||||
|
print_transaction(transaction)
|
||||||
|
|
||||||
flash("Success!", 'success')
|
flash("Success!", 'success')
|
||||||
return sell_page()
|
return sell_page()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user