forked from brmlab/brmbar-github
Search functionality added to Stock Management.
This commit is contained in:
parent
fb6eadf031
commit
ba4d8686f6
3 changed files with 94 additions and 9 deletions
|
@ -120,9 +120,9 @@ class ShopAdapter(QtCore.QObject):
|
|||
db.commit()
|
||||
return alist
|
||||
|
||||
@QtCore.Slot(result='QVariant')
|
||||
def itemList(self):
|
||||
alist = [ self.acct_inventory_map(a) for a in shop.account_list("inventory") ]
|
||||
@QtCore.Slot('QVariant', result='QVariant')
|
||||
def itemList(self, query):
|
||||
alist = [ self.acct_inventory_map(a) for a in shop.account_list("inventory", like_str="%%"+query+"%%") ]
|
||||
db.commit()
|
||||
return alist
|
||||
|
||||
|
@ -188,5 +188,5 @@ ctx.setContextProperty('shop', ShopAdapter())
|
|||
|
||||
view.setSource('brmbar-gui-qt4/main.qml')
|
||||
|
||||
view.showFullScreen()
|
||||
view.show()
|
||||
app.exec_()
|
||||
|
|
|
@ -6,6 +6,8 @@ Item {
|
|||
|
||||
property variant item_list_model
|
||||
|
||||
state: "normal"
|
||||
|
||||
BarcodeInput {
|
||||
color: "#00ff00" /* just for debugging */
|
||||
onAccepted: {
|
||||
|
@ -82,9 +84,11 @@ Item {
|
|||
id: new_item
|
||||
x: 65
|
||||
y: 582
|
||||
width: 360
|
||||
width: 281
|
||||
height: 83
|
||||
text: "New Item"
|
||||
fontSize: 0.768 * 60
|
||||
visible: page.state == "normal"
|
||||
onButtonClick: {
|
||||
loadPage("ItemEdit", { dbid: "" })
|
||||
}
|
||||
|
@ -97,11 +101,91 @@ Item {
|
|||
width: 360
|
||||
text: "Main Screen"
|
||||
onButtonClick: {
|
||||
loadPage("MainPage")
|
||||
if (page.state == "search")
|
||||
page.state = "normal"
|
||||
else
|
||||
loadPage("MainPage")
|
||||
}
|
||||
}
|
||||
|
||||
BarButton {
|
||||
id: search_button
|
||||
x: 353
|
||||
y: 582
|
||||
text: "Search"
|
||||
visible: page.state == "normal"
|
||||
onButtonClick: { page.state = "search" }
|
||||
}
|
||||
|
||||
BarKeyPad {
|
||||
id: search_pad
|
||||
x: 65
|
||||
y: 298
|
||||
opacity: 0
|
||||
}
|
||||
|
||||
Text {
|
||||
id: search_text
|
||||
x: 65
|
||||
y: 602
|
||||
color: "#ffff7c"
|
||||
text: search_pad.enteredText
|
||||
visible: page.state == "search"
|
||||
font.pixelSize: 0.768 * 46
|
||||
opacity: 0
|
||||
}
|
||||
|
||||
BarButton {
|
||||
id: query_button
|
||||
x: 353
|
||||
y: 582
|
||||
text: "Search"
|
||||
visible: page.state == "search"
|
||||
onButtonClick: {
|
||||
page.item_list_model = shop.itemList(search_pad.enteredText)
|
||||
item_list.model = page.item_list_model
|
||||
}
|
||||
}
|
||||
|
||||
states: [
|
||||
State {
|
||||
name: "normal"
|
||||
},
|
||||
State {
|
||||
name: "search"
|
||||
|
||||
PropertyChanges {
|
||||
target: item_list_container
|
||||
x: 66
|
||||
y: 166
|
||||
width: 899
|
||||
height: 132
|
||||
}
|
||||
|
||||
PropertyChanges {
|
||||
target: search_pad
|
||||
x: 65
|
||||
y: 298
|
||||
opacity: 1
|
||||
}
|
||||
|
||||
PropertyChanges {
|
||||
target: cancel
|
||||
text: "Back"
|
||||
}
|
||||
|
||||
PropertyChanges {
|
||||
target: search_text
|
||||
x: 65
|
||||
y: 582
|
||||
width: 528
|
||||
height: 83
|
||||
opacity: 1
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Component.onCompleted: {
|
||||
item_list_model = shop.itemList()
|
||||
item_list_model = shop.itemList("")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,10 +131,11 @@ class Shop:
|
|||
def inventory_balance_str(self):
|
||||
return self.currency.str(self.inventory_balance())
|
||||
|
||||
def account_list(self, acctype):
|
||||
def account_list(self, acctype, like_str="%%"):
|
||||
"""list all accounts (people or items, as per acctype)"""
|
||||
accts = []
|
||||
cur = self.db.execute_and_fetchall("SELECT id FROM accounts WHERE acctype = %s ORDER BY name ASC", [acctype])
|
||||
cur = self.db.execute_and_fetchall("SELECT id FROM accounts WHERE acctype = %s AND name ILIKE %s ORDER BY name ASC", [acctype, like_str])
|
||||
#FIXME: sanitize input like_str ^
|
||||
for inventory in cur:
|
||||
accts += [ Account.load(self.db, id = inventory[0]) ]
|
||||
return accts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue