Beispiel #1
0
                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)
                        db.add_category_item(item, cat)
                print "%d,%d,%d,%.2f,%.2f,%.2f,%d,%.2f,%s,%s" % (
                    itemid,
                    item.get_price_id(),
                    dist.get_id(),
                    d_i.get_wholesale_price(),
                    d_i.get_case_size(),
                    each_cost,
                    margin,
                    cost,
                    db.get_unit(item_price.get_sale_unit_id()),
                    db.get_item_info_page_link(itemid),
                )

    else:
        raise Exception("incorrect arguments. given %s" % (form.keys()))
elif action == "get-string":
    if "id" in form:
        item = db.get_item(int(form.getvalue("id")))
        print item
    else:
        raise Exception("incorrect arguments. need id. given %s" % (form.keys()))
elif action == "get-margin":
    if "item_id" in form and "dist_id" in form:
        item = db.get_item(int(form.getvalue("item_id")))
        distributor = db.get_distributor(int(form.getvalue("dist_id")))
Beispiel #2
0
        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')
    # prints out the following for each item: "id,dist_id,each_cost,margin"
    if "price_id" in form:
        price_id = int(form.getvalue("price_id"))
        for item,dist in db.get_items_by_price(price_id):
            dist_item = db.get_distributor_item(item, dist)