From 5ac08ac318275b5f9acacbb96485c09e9a8ea055 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 24 Sep 2012 03:53:19 +0200 Subject: [PATCH] brmbar v3 ShopAdapter: Factor out acct_debt_map(), acct_inventory_map() methods --- brmbar3/brmbar-gui-qt4.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/brmbar3/brmbar-gui-qt4.py b/brmbar3/brmbar-gui-qt4.py index 73eda65..a0cb280 100755 --- a/brmbar3/brmbar-gui-qt4.py +++ b/brmbar3/brmbar-gui-qt4.py @@ -13,6 +13,19 @@ class ShopAdapter(QtCore.QObject): def __init__(self): QtCore.QObject.__init__(self) + def acct_debt_map(self, acct): + map = acct.__dict__.copy() + map["balance"] = str(acct.balance()) + map["negbalance"] = str(-acct.balance()) + map["negbalance_str"] = acct.negbalance_str() + return map + + def acct_inventory_map(self, acct): + buy, sell = acct.currency.rates(currency) + map = acct.__dict__.copy() + map["price"] = str(sell) + return map + @QtCore.Slot(str, result='QVariant') def barcodeInput(self, barcode): """ Evaluate barcode received on input @@ -32,16 +45,9 @@ class ShopAdapter(QtCore.QObject): if acct is None: return None if acct.acctype == 'debt': - map = acct.__dict__.copy() - map["balance"] = str(acct.balance()) - map["negbalance"] = str(-acct.balance()) - map["negbalance_str"] = acct.negbalance_str() - return map + return self.acct_debt_map(acct) elif acct.acctype == "inventory": - buy, sell = acct.currency.rates(currency) - map = acct.__dict__.copy() - map["price"] = str(sell) - return map + return self.acct_inventory_map(acct) else: return None