From a4c37ce8137afec6db1960c22b1c41d0b8ca5c35 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 5 Oct 2011 12:28:29 +0200 Subject: [PATCH] client-barcode: Add command classes --- client-barcode/freitagskasse.py | 1 + client-barcode/freitagslib/commands.py | 35 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 client-barcode/freitagslib/commands.py diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index bbd31a6..08a998d 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -6,6 +6,7 @@ from __future__ import print_function import freitagslib.network as net +from freitagslib.commands import BuyCommand, DepositCommand import sys import decimal diff --git a/client-barcode/freitagslib/commands.py b/client-barcode/freitagslib/commands.py new file mode 100644 index 0000000..01d48c9 --- /dev/null +++ b/client-barcode/freitagslib/commands.py @@ -0,0 +1,35 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2011 Sebastian Pipping +# Licensed under GPL v3 or later + +import freitagslib.network as net + + +class Command(object): + def difference(self): + return self._difference + + +class DepositCommand(Command): + def __init__(self, amount): + self._difference = amount + + def run(self, user_name): + net.deposit(self._difference, DEPOSIT_CASH, user_name) + + def label(self): + return '%.2f Euro einzahlen' % self._difference + + +class BuyCommand(Command): + def __init__(self, item): + self.item = item + self._difference = item.price + + def run(self, user_name): + net.buy_item(self.item.id, user_name) + + def label(self): + return self.item.name