forked from brmlab/brmbar-github
brmbar v3 ShopAdapter: Factor out acct_debt_map(), acct_inventory_map() methods
This commit is contained in:
parent
71abc6ca66
commit
5ac08ac318
1 changed files with 15 additions and 9 deletions
|
@ -13,6 +13,19 @@ class ShopAdapter(QtCore.QObject):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtCore.QObject.__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')
|
@QtCore.Slot(str, result='QVariant')
|
||||||
def barcodeInput(self, barcode):
|
def barcodeInput(self, barcode):
|
||||||
""" Evaluate barcode received on input
|
""" Evaluate barcode received on input
|
||||||
|
@ -32,16 +45,9 @@ class ShopAdapter(QtCore.QObject):
|
||||||
if acct is None:
|
if acct is None:
|
||||||
return None
|
return None
|
||||||
if acct.acctype == 'debt':
|
if acct.acctype == 'debt':
|
||||||
map = acct.__dict__.copy()
|
return self.acct_debt_map(acct)
|
||||||
map["balance"] = str(acct.balance())
|
|
||||||
map["negbalance"] = str(-acct.balance())
|
|
||||||
map["negbalance_str"] = acct.negbalance_str()
|
|
||||||
return map
|
|
||||||
elif acct.acctype == "inventory":
|
elif acct.acctype == "inventory":
|
||||||
buy, sell = acct.currency.rates(currency)
|
return self.acct_inventory_map(acct)
|
||||||
map = acct.__dict__.copy()
|
|
||||||
map["price"] = str(sell)
|
|
||||||
return map
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue