mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 21:04:00 +02:00
brmbar-qt4: Add LIMIT_BALANCE(=-200) as a lower limit of user credit
This commit is contained in:
parent
84881dece3
commit
1c0e51a246
2 changed files with 15 additions and 0 deletions
|
@ -8,6 +8,9 @@ from brmbar import Database
|
||||||
|
|
||||||
import brmbar
|
import brmbar
|
||||||
|
|
||||||
|
# User credit balance limit; sale will fail when balance is below this limit.
|
||||||
|
LIMIT_BALANCE = -200
|
||||||
|
|
||||||
|
|
||||||
class ShopAdapter(QtCore.QObject):
|
class ShopAdapter(QtCore.QObject):
|
||||||
""" Interface between QML and the brmbar package """
|
""" Interface between QML and the brmbar package """
|
||||||
|
@ -70,6 +73,11 @@ class ShopAdapter(QtCore.QObject):
|
||||||
db.commit()
|
db.commit()
|
||||||
return acct
|
return acct
|
||||||
|
|
||||||
|
@QtCore.Slot('QVariant', 'QVariant', result='QVariant')
|
||||||
|
def canSellItem(self, itemid, userid):
|
||||||
|
user = brmbar.Account.load(db, id = userid)
|
||||||
|
return -user.balance() > LIMIT_BALANCE
|
||||||
|
|
||||||
@QtCore.Slot('QVariant', 'QVariant', result='QVariant')
|
@QtCore.Slot('QVariant', 'QVariant', result='QVariant')
|
||||||
def sellItem(self, itemid, userid):
|
def sellItem(self, itemid, userid):
|
||||||
user = brmbar.Account.load(db, id = userid)
|
user = brmbar.Account.load(db, id = userid)
|
||||||
|
@ -99,6 +107,11 @@ class ShopAdapter(QtCore.QObject):
|
||||||
db.commit()
|
db.commit()
|
||||||
return balance
|
return balance
|
||||||
|
|
||||||
|
@QtCore.Slot('QVariant', result='QVariant')
|
||||||
|
def balance_user(self, userid):
|
||||||
|
user = brmbar.Account.load(db, id=userid)
|
||||||
|
return user.negbalance_str()
|
||||||
|
|
||||||
@QtCore.Slot(result='QVariant')
|
@QtCore.Slot(result='QVariant')
|
||||||
def balance_cash(self):
|
def balance_cash(self):
|
||||||
balance = shop.cash.balance_str()
|
balance = shop.cash.balance_str()
|
||||||
|
|
|
@ -58,6 +58,8 @@ Item {
|
||||||
if (acct.acctype == "cash") { //Copied from BarButton.onButtonClick
|
if (acct.acctype == "cash") { //Copied from BarButton.onButtonClick
|
||||||
shop.sellItemCash(dbid)
|
shop.sellItemCash(dbid)
|
||||||
status_text.setStatus("Sold! Put " + price + " Kč in the money box.", "#ffff7c")
|
status_text.setStatus("Sold! Put " + price + " Kč in the money box.", "#ffff7c")
|
||||||
|
} else if (!shop.canSellItem(dbid, acct.id)) {
|
||||||
|
status_text.setStatus("NOT SOLD! "+acct.name+"'s credit is TOO LOW: "+shop.balance_user(acct.id), "#ff4444")
|
||||||
} else {
|
} else {
|
||||||
var balance = shop.sellItem(dbid, acct.id)
|
var balance = shop.sellItem(dbid, acct.id)
|
||||||
status_text.setStatus("Sold! "+acct.name+"'s credit is "+balance+".", "#ffff7c")
|
status_text.setStatus("Sold! "+acct.name+"'s credit is "+balance+".", "#ffff7c")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue