Skip to content

Commit

Permalink
REFACTOR payment: enforce Decimal type
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmax committed May 1, 2017
1 parent 163a145 commit 7b0c1d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions FabLabKasse/UI/PayupCashDialogCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class PayupCashDialog(QtGui.QDialog, Ui_PayupCashDialog):
def __init__(self, parent, amount_total, cfg):
"""
payment method dialog for automatic cash payin and payout
:param parent: parent widget passed on to QtGui.QDialog
:param amount_total: amount to pay
:type amount_total: Decimal
:param cfg: config from ScriptHelper.getConfig()
"""
QtGui.QDialog.__init__(self, parent)
Expand All @@ -49,6 +52,7 @@ def __init__(self, parent, amount_total, cfg):
self.pushButton_acceptLowPayout.setVisible(False)
self.pushButton_receipt.setVisible(False)
self.pushButton_receipt.clicked.connect(self.accept_and_print_receipt)
assert isinstance(amount_total, Decimal)
assert amount_total % Decimal("0.01") == 0
self.centsToPay = int(100 * amount_total)
self.centsToPayOut = None
Expand Down
4 changes: 3 additions & 1 deletion FabLabKasse/shopping/payment_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class AbstractPaymentMethod(object):
__metaclass__ = ABCMeta

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
assert isinstance(amount_to_pay, Decimal)
self.cfg = cfg
self.successful = None
self.amount_paid = None
Expand Down Expand Up @@ -172,6 +172,8 @@ def execute_and_store(self):
If possible, only override _show_dialog and not this method.
"""
self._show_dialog()
assert isinstance(self.amount_paid, (Decimal, int))
assert isinstance(self.amount_returned, (Decimal, int))
assert self.amount_paid >= self.amount_returned
if self.successful:
assert self.amount_paid >= self.amount_to_pay
Expand Down

0 comments on commit 7b0c1d2

Please sign in to comment.