Skip to content

Commit

Permalink
Made support-email configurable, fixes #100
Browse files Browse the repository at this point in the history
 - needs testing,
 - is vulnerable to #63

This commit contains

9d1b4de
Fixed syntax, TODO: cfg

and

0ffd19a
FIX pass cfg object into payment_methods
  • Loading branch information
sedrubal authored and patkan committed Jan 16, 2016
1 parent a159b0f commit 1f2531e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
5 changes: 3 additions & 2 deletions FabLabKasse/UI/PaymentMethodDialogCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PaymentMethodDialog(QtGui.QDialog, Ui_PaymentMethodDialog):
def __init__(self, parent, cfg, amount):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.cfg = cfg

self.method = None

Expand All @@ -41,7 +42,7 @@ def __init__(self, parent, cfg, amount):
button = Qt.QPushButton(method.get_title())
button.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
button.clicked.connect(functools.partial(self.acceptAndSetMethod, method)) # cannot use lambda here because variable method will change in next iteration... python is counterintuitive here....
button.setVisible(method.is_enabled(cfg))
button.setVisible(method.is_enabled(self.cfg))
self.layout_methods.addWidget(button)

self.label_betrag.setText(self.parent().shoppingBackend.format_money(amount))
Expand All @@ -52,4 +53,4 @@ def acceptAndSetMethod(self, method):
self.accept()

def getSelectedMethodInstance(self, parent, shopping_backend, amount_to_pay):
return self.method(parent, shopping_backend, amount_to_pay)
return self.method(parent, shopping_backend, amount_to_pay, self.cfg)
13 changes: 10 additions & 3 deletions FabLabKasse/UI/PayupCashDialogCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@

class PayupCashDialog(QtGui.QDialog, Ui_PayupCashDialog):

def __init__(self, parent, amount_total):
"""payment method dialog for automatic cash payin and payout"""
def __init__(self, parent, amount_total, cfg):
"""
payment method dialog for automatic cash payin and payout
:param cfg: config from ScriptHelper.getConfig()
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
# maximize window - WORKAROUND because showMaximized() doesn't work
Expand All @@ -51,6 +54,7 @@ def __init__(self, parent, amount_total):
self.centsReceived = None
self.centsPaidOut = None
self.returnDonated = False
self.cfg = cfg
# The finish button doesn't print a receipt, only the "print receipt and finish" one.
# Sometimes the later logic still forces receipt printing (e.g. payment aborted, not everything paid back)
self.receipt_wanted = False
Expand Down Expand Up @@ -271,7 +275,10 @@ def update(self):
text = text + u" <p>Ein Rest von {0} konnte leider nicht zurückgezahlt werden.</p>".format(PayupCashDialog.formatCent(self.centsToPayOut - self.centsPaidOut))
if self.centsToPay > 0: # payment not aborted
text += u"<p>Bitte das Aufräumen nicht vergessen!</p>"
text = text + u'<p style="font-size:14px"> Sollte etwas nicht stimmen, benachrichtige bitte sofort einen Betreuer und melde dich bei [email protected].</p></html>'
email = self.cfg.get('general', 'support_mail')
text += u'<p style="font-size:14px"> Sollte etwas nicht stimmen, ' + \
u'benachrichtige bitte sofort einen Betreuer und melde dich ' + \
u'bei {}.</p></html>'.format(email)
self.label_status.setText(text)
self.pushButton_finish.setVisible(True)
# only ask for receipt if something was paid
Expand Down
3 changes: 3 additions & 0 deletions FabLabKasse/config.ini.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[general]
; support mail will be displayed when error occur
support_mail = [email protected]

; Path to sqlite3 file
db_file = development.sqlite3

Expand Down
7 changes: 4 additions & 3 deletions FabLabKasse/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,10 @@ def askUser():
# TOOD show amount returned on receipt (needs some rework, because it is not yet stored in the order and so we cannot re-print receipts)
self.shoppingBackend.print_receipt(paymentmethod.receipt_order_id)
except PrinterError, e:
QtGui.QMessageBox.warning(self, "Quittung", "Drucker scheint offline zu sein." +
"\nFalls du wirklich eine Quittung brauchst, melde dich bei " +
"[email protected] mit Datum, Uhrzeit und Betrag.")
email = cfg.get('general', 'support_mail')
QtGui.QMessageBox.warning(self, "Quittung", u"Drucker scheint offline zu sein.\n"
u"Falls du wirklich eine Quittung brauchst, melde dich bei "
u"{} mit Datum, Uhrzeit und Betrag.".format(email))
logging.warning("printing receipt failed: {0}".format(repr(e)))
if paymentmethod.successful:
paymentmethod.show_thankyou()
Expand Down
7 changes: 4 additions & 3 deletions FabLabKasse/scriptHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ def myNewExceptionHook(exctype, value, tb):
import datetime
# logging.exception()
try:
cfg = getConfig()
email = cfg.get('general', 'support_mail')
msgbox = QtGui.QMessageBox()
txt = u"Entschuldigung, das Programm wird wegen eines Fehlers beendet."
infotxt = u"Wenn dir Rückgeld entgangen ist, melde dich bei [email protected] und gebe " + \
u"neben einer Fehlerbeschreibung folgende Uhrzeit an: "
infotxt += u"\n{0}.".format(str(datetime.datetime.today()))
infotxt = u"""Wenn dir Rückgeld entgangen ist, melde dich bei {} und gebe neben einer Fehlerbeschreibung folgende Uhrzeit an:
{0}.""".format(email, str(datetime.datetime.today()))
detailtxt = u"{0}\n{1}".format(str(datetime.datetime.today()), "".join(
traceback.format_exception(exctype, value, tb, limit=10)))
logging.fatal(txt)
Expand Down
23 changes: 12 additions & 11 deletions FabLabKasse/shopping/backend/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def format_money(amount):

class Category(object):
"""represents a category of Products"""

def __init__(self, categ_id, name, parent_id=None):
self.categ_id = categ_id
self.name = name
Expand All @@ -131,11 +131,11 @@ def __repr__(self):
class Product(object):

"""simple representation for a product
:param prod_id: numeric unique product ID
:type prod_id: int
:param categ_id: category ID of product, or None if the product is not directly visible
TODO hide these products from search, or a more explicit solution
:type categ_id: int | None
:param name: Name of product
Expand All @@ -158,7 +158,7 @@ class Product(object):
"""

def __init__(self, prod_id, name, price, unit, location, categ_id=None, qty_rounding=0, text_entry_required=False):

self.prod_id = prod_id
self.name = name
assert isinstance(price, (Decimal, int))
Expand Down Expand Up @@ -190,11 +190,11 @@ class OrderLine(object):
:param Decimal price_subtotal: price for ``qty`` * ``unit`` of this product
:param boolean delete_if_zero_qty: if the qty is zero and the user starts adding something else, then remove this line
[ usually True, set to False for products that also may as comment limes costing nothing ]
"""

def __init__(self, order_line_id, qty, unit, name, price_per_unit, price_subtotal, delete_if_zero_qty=True):

self.order_line_id = order_line_id
Expand Down Expand Up @@ -241,7 +241,7 @@ class AbstractShoppingBackend(object):
__metaclass__ = ABCMeta

def __init__(self, cfg):
"""cfg: config from ScriptHelper.getConfig()"""
""":param cfg: config from ScriptHelper.getConfig()"""
self.cfg = cfg

def format_money(self, amount):
Expand Down Expand Up @@ -447,12 +447,13 @@ def pay_order_on_client(self, client):
new_debt = debt + self.get_current_total()
debt_limit = client.get_debt_limit()
if new_debt > debt_limit:
email = self.cfg.get('general', 'support_mail')
raise DebtLimitExceeded(
u"Der Kontostand wäre mit dieser Buchung über seinem Limit.\n" +
u"Der Kontostand wäre mit dieser Buchung über seinem Limit.\n"
u"Aktuelles Guthaben: {:.2f}\n"
u"Schuldengrenze für dieses Konto: {:.2f}\n\n"
u"Bie Fragen bitte an [email protected] wenden."
.format(-debt, debt_limit))
u"Bie Fragen bitte an {} wenden."
.format(-debt, debt_limit, email))

self._pay_order_on_client_unchecked(client)

Expand Down
9 changes: 6 additions & 3 deletions FabLabKasse/shopping/payment_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@
class AbstractPaymentMethod(object):

"""interface for payment methods
:param QWidget parent: handle for main window - for Qt usage
:param FabLabKasse.shopping.backend.abstract.AbstractShoppingBackend shopping_backend: ShoppingBackend instance
:param Decimal amount_to_pay: requested amount (rounded to cents)
:param cfg: config object
"""
__metaclass__ = ABCMeta

def __init__(self, parent, shopping_backend, amount_to_pay):
def __init__(self, parent, shopping_backend, amount_to_pay, cfg):

self.parent = parent
self.shopping_backend = shopping_backend
self.amount_to_pay = amount_to_pay
self.cfg = cfg
self.successful = None
self.amount_paid = None
self.amount_returned = None
Expand Down Expand Up @@ -307,7 +309,8 @@ def get_title():
return "Bargeld (Automatenkasse)"

def _show_dialog(self):
pay_diag = PayupCashDialog(parent=self.parent, amount_total=self.amount_to_pay)
pay_diag = PayupCashDialog(parent=self.parent,
amount_total=self.amount_to_pay, cfg=self.cfg)
ok = bool(pay_diag.exec_())
paid_amount = pay_diag.getPaidAmount()
self.amount_paid = paid_amount # TODO add amount_returned
Expand Down

0 comments on commit 1f2531e

Please sign in to comment.