dist_item = db.get_distributor_item_byid(int(form.getvalue('dist_item_id'))) dist_item_id = dist_item.get_dist_item_id() wholesale_price = dist_item.get_wholesale_price() case_size = dist_item.get_case_size() case_unit_id = dist_item.get_case_unit_id() if 'distitemid' in form: dist_item_id = form.getvalue('distitemid') if 'caseprice' in form: wholesale_price = float(form.getvalue('caseprice')) if 'casesize' in form: case_size = float(form.getvalue('casesize')) if 'caseunit' in form: case_unit_id = int(form.getvalue('caseunit')) db.update_distributor_item(dist_item, dist_item_id, wholesale_price, case_size, case_unit_id) else: raise Exception ('no distributor_item id given') elif action == 'remove_byid': # temporary hack until things get sorted out with item_info (should only need this) if "dist_item_id" in form: db.remove_distributor_item_byid(int(form.getvalue('dist_item_id'))) else: raise Exception ('no distributor_item id given') elif action == 'query-margin': # temporary hack until things get sorted out with item_info (should only need this) if "dist_item_id" in form: dist_item = db.get_distributor_item_byid(int(form.getvalue('dist_item_id'))) each_cost = dist_item.get_each_cost() item = db.get_item(dist_item.get_item_id()) dist = db.get_distributor(dist_item.get_dist_id()) margin = db.get_distributor_item_margin(item,dist,dist_item) print '%.2f, %d' % (each_cost, margin)
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") if "wholesale_price" in form: wholesale_price = float(form.getvalue("wholesale_price")) if "case_size" in form: case_size = float(form.getvalue("case_size")) if "case_unit" in form: case_unit = form.getvalue("case_unit") case_unitid = db.get_unit_byname(case_unit).get_id() db.update_distributor_item(d_i, ditemid, wholesale_price, case_size, case_unitid) item = db.get_item(itemid) each_cost = d_i.get_each_cost() op_price = item.get_price() tax = item.get_tax_value() if (op_price - tax) != 0: margin = (1.0 - each_cost / (op_price - tax)) * 100 else: margin = 100 item_price = db.get_price(item.get_price_id()) cost = item_price.get_unit_cost() if "categories" in form: cat_ids_list = form.getvalue("categories") cat_ids = filter(lambda x: x.isdigit(), cat_ids_list.split(",")) # only get valid digits for c_id in cat_ids: cat = db.get_category(c_id)