and "taxcat" in form and ("price" in form and "price_unit" in form or "price_id" in form) and "count" in form and "itemsize" in form and "size_unit" in form and "distributor" in form ): name = form.getvalue("name") taxcatname = form.getvalue("taxcat").split(" ")[0] # string representation of taxcat includes a (%.2f%%) not_valid = False p_id = int(form.getvalue("price_id")) if p_id == 0: price = float(form.getvalue("price")) price_unit = form.getvalue("price_unit") else: if not db.is_price(p_id): not_valid = True else: price = p_id price_unit = None if not_valid: print "Error: invalid price" 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)
action = form.getvalue("action") if action == 'price': if "price_id" in form and "price" in form: price = db.get_price(int(form.getvalue("price_id"))) db.set_price(price, float(form.getvalue("price"))) else: raise Exception ('invalid arguments. need price_id and price. given %s' % form.keys()) elif action == 'group': if "price_id" in form and "item_id" in form: newid = form.getvalue('price_id') itemid = form.getvalue('item_id') if newid.isdigit() and itemid.isdigit(): newid = int(newid) itemid = int(itemid) if db.is_price(newid): item = db.get_item(itemid) old = item.get_price_id() db.set_item_price(item,newid) price = db.get_price(newid) sale_unit = db.get_unit(price.get_sale_unit_id()) print '%d,%d,%.2f,%d,%s' % (old,db.price_item_count(old),price.get_unit_cost(), price.get_id(),sale_unit) else: raise Exception ('price_id %d not currently in database' % (newid)) else: raise Exception ('invalid price_id or item_id') else: raise Exception ('invalid arguments. need price_id and item_id. given %s' % (form.keys())) elif action == 'query': # returns a string containing information about all (item,distributor) pairs with the given price_id # prints the string as info about one item per line (separated with '\n')