mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 21:04:00 +02:00
Merge branch 'master' of github.com:brmlab/brmbar
This commit is contained in:
commit
48c583a81c
2 changed files with 29 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from PySide import QtCore, QtGui, QtDeclarative
|
from PySide import QtCore, QtGui, QtDeclarative
|
||||||
|
|
||||||
|
@ -8,6 +9,15 @@ from brmbar import Database
|
||||||
|
|
||||||
import brmbar
|
import brmbar
|
||||||
|
|
||||||
|
# User credit balance limit; sale will fail when balance is below this limit.
|
||||||
|
LIMIT_BALANCE = -200
|
||||||
|
# When below this credit balance, an alert hook script (see below) is run.
|
||||||
|
ALERT_BALANCE = 0
|
||||||
|
# This script is executed when a user is buying things and their balance is
|
||||||
|
# below LIMIT_BALANCE (with argument "limit") or below ALERT_BALANCE
|
||||||
|
# (with argument "alert").
|
||||||
|
ALERT_SCRIPT = "./alert.sh"
|
||||||
|
|
||||||
|
|
||||||
class ShopAdapter(QtCore.QObject):
|
class ShopAdapter(QtCore.QObject):
|
||||||
""" Interface between QML and the brmbar package """
|
""" Interface between QML and the brmbar package """
|
||||||
|
@ -70,6 +80,18 @@ 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)
|
||||||
|
if -user.balance() > ALERT_BALANCE:
|
||||||
|
return True
|
||||||
|
elif -user.balance() > LIMIT_BALANCE:
|
||||||
|
subprocess.call(["sh", ALERT_SCRIPT, "alert"])
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
subprocess.call(["sh", ALERT_SCRIPT, "limit"])
|
||||||
|
return False
|
||||||
|
|
||||||
@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 +121,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