brmbarv3 ItemEdit: Add support for adding new items

This commit is contained in:
Petr Baudis 2012-09-28 23:21:09 +02:00
parent a775c24cbc
commit 278a869ba3
4 changed files with 54 additions and 11 deletions

View file

@ -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

View file

@ -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)

View file

@ -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,18 +300,35 @@ 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 == "") {
} else { res = shop.newItem(info)
status_text.setStatus("Changes saved", "#ffff7c") 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") loadPage("StockMgmt")
} }
} }
}
BarButton { BarButton {
id: cancel id: cancel
@ -322,7 +343,11 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
if (dbid != "") {
info = shop.loadAccount(dbid) info = shop.loadAccount(dbid)
} else {
info = { "name": "", "dbid": "", "buy_price": "", "price": "", "balance": 0 };
}
} }
states: [ states: [

View file

@ -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 {