mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-08 05:14:00 +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
|
||||
+ Use for credit charge
|
||||
+ Use for withdrawal
|
||||
/ Restocking view (Stock management)
|
||||
+ Restocking view (Stock management)
|
||||
+ Item picker with edit button
|
||||
+ Item editor (name, buy price, sale price, quantity)
|
||||
+ Item-barcode assignment
|
||||
- Support for adding new items
|
||||
+ Support for adding new items
|
||||
+ Alphanumeric manual entry support
|
||||
+ Use in item editor
|
||||
- Withdrawal for brmbar receipts
|
||||
|
|
|
@ -117,7 +117,22 @@ class ShopAdapter(QtCore.QObject):
|
|||
cost = ""
|
||||
if (acct.balance() < int(invmap["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")
|
||||
shop = brmbar.Shop.new_with_defaults(db)
|
||||
|
|
|
@ -24,6 +24,10 @@ Item {
|
|||
/* TODO: Allow override. */
|
||||
return
|
||||
}
|
||||
if (info.dbid == "") {
|
||||
status_text.setStatus("Press [Create] first", "#ff4444")
|
||||
return
|
||||
}
|
||||
shop.addBarcode(dbid, barcode)
|
||||
status_text.setStatus("Barcode added.", "#ffff7c")
|
||||
}
|
||||
|
@ -296,18 +300,35 @@ Item {
|
|||
x: 65
|
||||
y: 582
|
||||
width: 360
|
||||
text: "Save"
|
||||
text: dbid == "" ? "Create" : "Save"
|
||||
onButtonClick: {
|
||||
info["name"] = name
|
||||
var res = shop.saveItem(dbid, info)
|
||||
if (res.cost) {
|
||||
status_text.setStatus("Restocked! Take " + res.cost + " from the money box.", "#ffff7c")
|
||||
} else {
|
||||
status_text.setStatus("Changes saved", "#ffff7c")
|
||||
var xi = info; xi["name"] = page.name; info = xi
|
||||
|
||||
var res;
|
||||
if (dbid == "") {
|
||||
res = shop.newItem(info)
|
||||
if (!res) {
|
||||
status_text.setStatus("Please fill all values first.", "#ff4444")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BarButton {
|
||||
id: cancel
|
||||
|
@ -322,7 +343,11 @@ Item {
|
|||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (dbid != "") {
|
||||
info = shop.loadAccount(dbid)
|
||||
} else {
|
||||
info = { "name": "", "dbid": "", "buy_price": "", "price": "", "balance": 0 };
|
||||
}
|
||||
}
|
||||
|
||||
states: [
|
||||
|
|
|
@ -87,6 +87,9 @@ Item {
|
|||
width: 360
|
||||
text: "Add Item"
|
||||
fontSize: 44
|
||||
onButtonClick: {
|
||||
loadPage("ItemEdit", { name: "", dbid: "" })
|
||||
}
|
||||
}
|
||||
|
||||
BarButton {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue