Skip to content

Commit b1cb9eb

Browse files
author
sedrubal
committed
Merge branch 'support-mail-config' into development
Fixes #100 and #108
2 parents 174cff8 + a741608 commit b1cb9eb

File tree

7 files changed

+63
-28
lines changed

7 files changed

+63
-28
lines changed

FabLabKasse/UI/PaymentMethodDialogCode.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PaymentMethodDialog(QtGui.QDialog, Ui_PaymentMethodDialog):
2828
def __init__(self, parent, cfg, amount):
2929
QtGui.QDialog.__init__(self, parent)
3030
self.setupUi(self)
31+
self.cfg = cfg
3132

3233
self.method = None
3334

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

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

5455
def getSelectedMethodInstance(self, parent, shopping_backend, amount_to_pay):
55-
return self.method(parent, shopping_backend, amount_to_pay)
56+
return self.method(parent, shopping_backend, amount_to_pay, self.cfg)

FabLabKasse/UI/PayupCashDialogCode.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
import functools
2222
import logging
2323
from decimal import Decimal
24+
from ConfigParser import Error as ConfigParserError
2425

2526

2627
class PayupCashDialog(QtGui.QDialog, Ui_PayupCashDialog):
2728

28-
def __init__(self, parent, amount_total):
29-
"""payment method dialog for automatic cash payin and payout"""
29+
def __init__(self, parent, amount_total, cfg):
30+
"""
31+
payment method dialog for automatic cash payin and payout
32+
:param cfg: config from ScriptHelper.getConfig()
33+
"""
3034
QtGui.QDialog.__init__(self, parent)
3135
self.setupUi(self)
3236
# maximize window - WORKAROUND because showMaximized() doesn't work
@@ -51,6 +55,7 @@ def __init__(self, parent, amount_total):
5155
self.centsReceived = None
5256
self.centsPaidOut = None
5357
self.returnDonated = False
58+
self.cfg = cfg
5459
# The finish button doesn't print a receipt, only the "print receipt and finish" one.
5560
# Sometimes the later logic still forces receipt printing (e.g. payment aborted, not everything paid back)
5661
self.receipt_wanted = False
@@ -271,7 +276,13 @@ def update(self):
271276
text = text + u" <p>Ein Rest von {0} konnte leider nicht zurückgezahlt werden.</p>".format(PayupCashDialog.formatCent(self.centsToPayOut - self.centsPaidOut))
272277
if self.centsToPay > 0: # payment not aborted
273278
text += u"<p>Bitte das Aufräumen nicht vergessen!</p>"
274-
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>'
279+
text += u'<p style="font-size:14px"> Sollte etwas nicht stimmen, ' + \
280+
u'benachrichtige bitte sofort einen Betreuer'
281+
try:
282+
email = self.cfg.get('general', 'support_mail')
283+
text += u' und melde dich bei {}.</p></html>'.format(email)
284+
except ConfigParserError:
285+
text += '.</p></html>'
275286
self.label_status.setText(text)
276287
self.pushButton_finish.setVisible(True)
277288
# only ask for receipt if something was paid

FabLabKasse/config.ini.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[general]
2+
; support mail will be displayed when error occur
3+
support_mail = [email protected]
4+
25
; Path to sqlite3 file
36
db_file = development.sqlite3
47

FabLabKasse/gui.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from decimal import Decimal, DecimalException
4242
from PyQt4 import QtGui, QtCore, Qt
4343
import functools
44+
from ConfigParser import Error as ConfigParserError
4445

4546
from libs.flickcharm import FlickCharm
4647
from libs.pxss import pxss
@@ -632,9 +633,13 @@ def askUser():
632633
# 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)
633634
self.shoppingBackend.print_receipt(paymentmethod.receipt_order_id)
634635
except PrinterError, e:
635-
QtGui.QMessageBox.warning(self, "Quittung", "Drucker scheint offline zu sein." +
636-
"\nFalls du wirklich eine Quittung brauchst, melde dich bei " +
637-
"[email protected] mit Datum, Uhrzeit und Betrag.")
636+
try:
637+
email = cfg.get('general', 'support_mail')
638+
except ConfigParserError:
639+
email = u"einem zuständigen Betreuer"
640+
QtGui.QMessageBox.warning(self, "Quittung", u"Drucker scheint offline zu sein.\n"
641+
u"Falls du wirklich eine Quittung brauchst, melde dich bei "
642+
u"{} mit Datum, Uhrzeit und Betrag.".format(email))
638643
logging.warning("printing receipt failed: {0}".format(repr(e)))
639644
if paymentmethod.successful:
640645
paymentmethod.show_thankyou()

FabLabKasse/scriptHelper.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import portalocker
2727
import sqlite3
2828
from ConfigParser import ConfigParser
29+
from ConfigParser import Error as ConfigParserError
2930
import codecs
3031
from PyQt4 import QtGui
3132
import traceback
@@ -64,11 +65,16 @@ def myNewExceptionHook(exctype, value, tb):
6465
import datetime
6566
# logging.exception()
6667
try:
68+
cfg = getConfig()
69+
try:
70+
email = cfg.get('general', 'support_mail')
71+
except ConfigParserError:
72+
logging.warning("could not read mail address from config in graphical except-hook.")
73+
email = "den Verantwortlichen"
6774
msgbox = QtGui.QMessageBox()
6875
txt = u"Entschuldigung, das Programm wird wegen eines Fehlers beendet."
69-
infotxt = u"Wenn dir Rückgeld entgangen ist, melde dich bei [email protected] und gebe " + \
70-
u"neben einer Fehlerbeschreibung folgende Uhrzeit an: "
71-
infotxt += u"\n{0}.".format(str(datetime.datetime.today()))
76+
infotxt = u"""Wenn dir Rückgeld entgangen ist, melde dich bei {0} und gebe neben einer
77+
Fehlerbeschreibung folgende Uhrzeit an:{1}.""".format(email, str(datetime.datetime.today()))
7278
detailtxt = u"{0}\n{1}".format(str(datetime.datetime.today()), "".join(
7379
traceback.format_exception(exctype, value, tb, limit=10)))
7480
logging.fatal(txt)

FabLabKasse/shopping/backend/abstract.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import locale
2828
import unittest
2929
import doctest
30+
from ConfigParser import Error as ConfigParserError
3031

3132
# counter for unique id values, use next(_id_counter) to get a new ID
3233
_id_counter = itertools.count()
@@ -80,6 +81,7 @@ def format_qty(qty):
8081
s = s.replace(".", locale.localeconv()['decimal_point'])
8182
return s
8283

84+
8385
def format_money(amount):
8486
"""format float as money string
8587
@@ -113,12 +115,12 @@ def format_money(amount):
113115
if formatted.endswith("0"):
114116
formatted = formatted[:-1]
115117

116-
return u'{} €'.format(formatted).replace('.', ',')
118+
return u'{0} €'.format(formatted).replace('.', ',')
117119

118120

119121
class Category(object):
120122
"""represents a category of Products"""
121-
123+
122124
def __init__(self, categ_id, name, parent_id=None):
123125
self.categ_id = categ_id
124126
self.name = name
@@ -131,11 +133,11 @@ def __repr__(self):
131133
class Product(object):
132134

133135
"""simple representation for a product
134-
136+
135137
:param prod_id: numeric unique product ID
136138
:type prod_id: int
137139
:param categ_id: category ID of product, or None if the product is not directly visible
138-
140+
139141
TODO hide these products from search, or a more explicit solution
140142
:type categ_id: int | None
141143
:param name: Name of product
@@ -158,7 +160,7 @@ class Product(object):
158160
"""
159161

160162
def __init__(self, prod_id, name, price, unit, location, categ_id=None, qty_rounding=0, text_entry_required=False):
161-
163+
162164
self.prod_id = prod_id
163165
self.name = name
164166
assert isinstance(price, (Decimal, int))
@@ -190,11 +192,11 @@ class OrderLine(object):
190192
:param Decimal price_subtotal: price for ``qty`` * ``unit`` of this product
191193
192194
:param boolean delete_if_zero_qty: if the qty is zero and the user starts adding something else, then remove this line
193-
194-
195+
196+
195197
[ usually True, set to False for products that also may as comment limes costing nothing ]
196198
"""
197-
199+
198200
def __init__(self, order_line_id, qty, unit, name, price_per_unit, price_subtotal, delete_if_zero_qty=True):
199201

200202
self.order_line_id = order_line_id
@@ -241,7 +243,7 @@ class AbstractShoppingBackend(object):
241243
__metaclass__ = ABCMeta
242244

243245
def __init__(self, cfg):
244-
"""cfg: config from ScriptHelper.getConfig()"""
246+
""":param cfg: config from ScriptHelper.getConfig()"""
245247
self.cfg = cfg
246248

247249
def format_money(self, amount):
@@ -447,12 +449,16 @@ def pay_order_on_client(self, client):
447449
new_debt = debt + self.get_current_total()
448450
debt_limit = client.get_debt_limit()
449451
if new_debt > debt_limit:
452+
try:
453+
email = self.cfg.get('general', 'support_mail')
454+
except ConfigParserError:
455+
email = u"einen zuständigen Betreuer"
450456
raise DebtLimitExceeded(
451-
u"Der Kontostand wäre mit dieser Buchung über seinem Limit.\n" +
452-
u"Aktuelles Guthaben: {:.2f}\n"
453-
u"Schuldengrenze für dieses Konto: {:.2f}\n\n"
454-
u"Bie Fragen bitte an [email protected] wenden."
455-
.format(-debt, debt_limit))
457+
u"Der Kontostand wäre mit dieser Buchung über seinem Limit.\n"
458+
u"Aktuelles Guthaben: {0:.2f}\n"
459+
u"Schuldengrenze für dieses Konto: {1:.2f}\n\n"
460+
u"Bie Fragen wende dich bitte an {2}."
461+
.format(-debt, debt_limit, email))
456462

457463
self._pay_order_on_client_unchecked(client)
458464

FabLabKasse/shopping/payment_methods.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,20 @@
4848
class AbstractPaymentMethod(object):
4949

5050
"""interface for payment methods
51-
51+
5252
:param QWidget parent: handle for main window - for Qt usage
5353
:param FabLabKasse.shopping.backend.abstract.AbstractShoppingBackend shopping_backend: ShoppingBackend instance
5454
:param Decimal amount_to_pay: requested amount (rounded to cents)
55+
:param cfg: config object
5556
"""
5657
__metaclass__ = ABCMeta
5758

58-
def __init__(self, parent, shopping_backend, amount_to_pay):
59+
def __init__(self, parent, shopping_backend, amount_to_pay, cfg):
5960

6061
self.parent = parent
6162
self.shopping_backend = shopping_backend
6263
self.amount_to_pay = amount_to_pay
64+
self.cfg = cfg
6365
self.successful = None
6466
self.amount_paid = None
6567
self.amount_returned = None
@@ -307,7 +309,8 @@ def get_title():
307309
return "Bargeld (Automatenkasse)"
308310

309311
def _show_dialog(self):
310-
pay_diag = PayupCashDialog(parent=self.parent, amount_total=self.amount_to_pay)
312+
pay_diag = PayupCashDialog(parent=self.parent,
313+
amount_total=self.amount_to_pay, cfg=self.cfg)
311314
ok = bool(pay_diag.exec_())
312315
paid_amount = pay_diag.getPaidAmount()
313316
self.amount_paid = paid_amount # TODO add amount_returned

0 commit comments

Comments
 (0)