mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-08 13:24:01 +02:00
brmbarv3 ItemEdit: Add support for adding new items
This commit is contained in:
parent
a775c24cbc
commit
278a869ba3
4 changed files with 54 additions and 11 deletions
|
@ -9,11 +9,11 @@
|
||||||
+ Numerical manual entry support
|
+ Numerical manual entry support
|
||||||
+ Use for credit charge
|
+ Use for credit charge
|
||||||
+ Use for withdrawal
|
+ Use for withdrawal
|
||||||
/ Restocking view (Stock management)
|
+ Restocking view (Stock management)
|
||||||
+ Item picker with edit button
|
+ Item picker with edit button
|
||||||
+ Item editor (name, buy price, sale price, quantity)
|
+ Item editor (name, buy price, sale price, quantity)
|
||||||
+ Item-barcode assignment
|
+ Item-barcode assignment
|
||||||
- Support for adding new items
|
+ Support for adding new items
|
||||||
+ Alphanumeric manual entry support
|
+ Alphanumeric manual entry support
|
||||||
+ Use in item editor
|
+ Use in item editor
|
||||||
- Withdrawal for brmbar receipts
|
- Withdrawal for brmbar receipts
|
||||||
|
|
|
@ -117,7 +117,22 @@ class ShopAdapter(QtCore.QObject):
|
||||||
cost = ""
|
cost = ""
|
||||||
if (acct.balance() < int(invmap["balance"])):
|
if (acct.balance() < int(invmap["balance"])):
|
||||||
cost = shop.buy_for_cash(acct, invmap["balance"] - acct.balance())
|
cost = shop.buy_for_cash(acct, invmap["balance"] - acct.balance())
|
||||||
return { "dbid": dbid, "cost": currency.str(cost) }
|
return { "dbid": dbid, "cost": (currency.str(cost) if cost != "" else "") }
|
||||||
|
|
||||||
|
@QtCore.Slot('QVariant', result='QVariant')
|
||||||
|
def newItem(self, invmap):
|
||||||
|
if (invmap["name"] == "" or invmap["price"] == "" or invmap["buy_price"] == ""):
|
||||||
|
return None
|
||||||
|
invcurrency = brmbar.Currency.create(db, invmap["name"])
|
||||||
|
invcurrency.update_sell_rate(currency, invmap["price"])
|
||||||
|
invcurrency.update_buy_rate(currency, invmap["buy_price"])
|
||||||
|
acct = brmbar.Account.create(db, invmap["name"], invcurrency, "inventory")
|
||||||
|
cost = ""
|
||||||
|
if (int(invmap["balance"]) > 0):
|
||||||
|
cost = shop.buy_for_cash(acct, invmap["balance"]) # implicit db.commit()
|
||||||
|
else:
|
||||||
|
db.commit()
|
||||||
|
return { "dbid": acct.id, "cost": (currency.str(cost) if cost != "" else "") }
|
||||||
|
|
||||||
db = psycopg2.connect("dbname=brmbar")
|
db = psycopg2.connect("dbname=brmbar")
|
||||||
shop = brmbar.Shop.new_with_defaults(db)
|
shop = brmbar.Shop.new_with_defaults(db)
|
||||||
|
|
|
@ -24,6 +24,10 @@ Item {
|
||||||
/* TODO: Allow override. */
|
/* TODO: Allow override. */
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (info.dbid == "") {
|
||||||
|
status_text.setStatus("Press [Create] first", "#ff4444")
|
||||||
|
return
|
||||||
|
}
|
||||||
shop.addBarcode(dbid, barcode)
|
shop.addBarcode(dbid, barcode)
|
||||||
status_text.setStatus("Barcode added.", "#ffff7c")
|
status_text.setStatus("Barcode added.", "#ffff7c")
|
||||||
}
|
}
|
||||||
|
@ -296,16 +300,33 @@ Item {
|
||||||
x: 65
|
x: 65
|
||||||
y: 582
|
y: 582
|
||||||
width: 360
|
width: 360
|
||||||
text: "Save"
|
text: dbid == "" ? "Create" : "Save"
|
||||||
onButtonClick: {
|
onButtonClick: {
|
||||||
info["name"] = name
|
var xi = info; xi["name"] = page.name; info = xi
|
||||||
var res = shop.saveItem(dbid, info)
|
|
||||||
if (res.cost) {
|
var res;
|
||||||
status_text.setStatus("Restocked! Take " + res.cost + " from the money box.", "#ffff7c")
|
if (dbid == "") {
|
||||||
|
res = shop.newItem(info)
|
||||||
|
if (!res) {
|
||||||
|
status_text.setStatus("Please fill all values first.", "#ff4444")
|
||||||
|
return
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
status_text.setStatus("Changes saved", "#ffff7c")
|
res = shop.saveItem(dbid, info)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.cost) {
|
||||||
|
status_text.setStatus((dbid == "" ? "Stocked!" : "Restocked!") + " Take " + res.cost + " from the money box.", "#ffff7c")
|
||||||
|
} else {
|
||||||
|
status_text.setStatus(dbid == "" ? "Item created" : "Changes saved", "#ffff7c")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dbid == "") {
|
||||||
|
dbid = res.dbid
|
||||||
|
var xi = info; xi["dbid"] = page.dbid; info = xi
|
||||||
|
} else {
|
||||||
|
loadPage("StockMgmt")
|
||||||
}
|
}
|
||||||
loadPage("StockMgmt")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +343,11 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
info = shop.loadAccount(dbid)
|
if (dbid != "") {
|
||||||
|
info = shop.loadAccount(dbid)
|
||||||
|
} else {
|
||||||
|
info = { "name": "", "dbid": "", "buy_price": "", "price": "", "balance": 0 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
|
|
|
@ -87,6 +87,9 @@ Item {
|
||||||
width: 360
|
width: 360
|
||||||
text: "Add Item"
|
text: "Add Item"
|
||||||
fontSize: 44
|
fontSize: 44
|
||||||
|
onButtonClick: {
|
||||||
|
loadPage("ItemEdit", { name: "", dbid: "" })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BarButton {
|
BarButton {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue