else: price = p_id price_unit = None if not_valid: print '<br /> Invalid price_id' else: count = int(form.getvalue('count')) plu = None itemsize = float(form.getvalue('itemsize')) sizeunit = form.getvalue('size_unit') if 'plu' in form: plu = form.getvalue('plu') itemid = db.add_item(name,itemsize, sizeunit, plu, count, price, taxcatname,price_unit) if 'barcode' in form: db.add_barcode_item(itemid, form.getvalue('barcode')) if 'distributor' in form: distname = form.getvalue('distributor') if db.is_distributor_byname(distname): item = db.get_item(itemid) dist = db.get_distributor_byname(distname) db.add_distributor_item(item, dist) d_i = db.get_distributor_item(item, dist) ditemid = 0 wholesale_price = 0 case_size = 0 case_unit = 'each' if 'dist_item_id' in form: ditemid = form.getvalue('dist_item_id')
else: raise Exception("incorrect arguments. need id and name. given %s" % (form.keys())) elif action == "barcode_byid": # hack to get around barcode if "barcode_id" in form and "new_barcode" in form: bc_id = int(form.getvalue("barcode_id")) db.set_barcode_item_byid(bc_id, form.getvalue("new_barcode")) else: raise Exception("incorrect arguments. need barcode_id and new_barcode. given %s" % (form.keys())) elif action == "barcode": if "id" in form and "newbarcode" in form and "oldbarcode" in form: itemid = int(form.getvalue("id")) if form.getvalue("oldbarcode") != "None": item = db.get_item(itemid) db.set_item_barcode(item, form.getvalue("oldbarcode"), form.getvalue("newbarcode")) else: db.add_barcode_item(itemid, form.getvalue("newbarcode")) else: raise Exception("incorrect arguments. need id, newbarcode, and oldbarcode. given %s" % (form.keys())) elif action == "size": if "id" in form and "size" in form: itemid = int(form.getvalue("id")) size = float(form.getvalue("size")) item = db.get_item(itemid) db.set_item_size(item, size) else: raise Exception("incorrect arguments. need id, size. given %s" % (form.keys())) elif action == "sizeunit": if "id" in form and "sizeunit" in form: size_unit = form.getvalue("sizeunit").strip() s_u = db.get_unit_byname(size_unit).get_id() item = db.get_item(int(form.getvalue("id")))
import cgi, sys import op_db_library as db def log_exception(*args): print "Error: %s" % (args[1],) sys.excepthook = log_exception print "Content-Type: text/plain\n" form = cgi.FieldStorage() action = form.getvalue("action") if action == "add": if "item_id" in form and "barcode" in form: itemid = int(form.getvalue("item_id")) item = db.get_item(itemid) barcode = form.getvalue("barcode") db.add_barcode_item(itemid, barcode) new_bcitem = db.get_barcode_item(item, barcode) print new_bcitem.get_id() else: raise Exception("missing either item_id or barcode. given:%s" % (form.keys())) elif action == "remove": if "bc_item_id" in form: db.remove_barcode_item_byid(int(form.getvalue("bc_item_id"))) else: raise Exception("bc_item_id not given") else: raise Exception("invalid action")