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

View file

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

View file

@ -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,16 +300,33 @@ 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")
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 {
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: {
info = shop.loadAccount(dbid)
if (dbid != "") {
info = shop.loadAccount(dbid)
} else {
info = { "name": "", "dbid": "", "buy_price": "", "price": "", "balance": 0 };
}
}
states: [

View file

@ -87,6 +87,9 @@ Item {
width: 360
text: "Add Item"
fontSize: 44
onButtonClick: {
loadPage("ItemEdit", { name: "", dbid: "" })
}
}
BarButton {