Exemple #1
0
        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")))
        db.set_item_size_unit(item, s_u)
    else:
        raise Exception("incorrect arguments. need id, sizeunit. given %s" % (form.keys()))
elif action == "sizeunit_byid":
    if "id" in form and "sizeunit" in form:
        item = db.get_item(int(form.getvalue("id")))
        db.set_item_size_unit(item, int(form.getvalue("sizeunit")))
    else:
        raise Exception("incorrect arguments. need id, sizeunit. given %s" % (form.keys()))
elif action == "add":
    if (
        "name" in form
        and "taxcat" in form
        and ("price" in form and "price_unit" in form or "price_id" in form)
                    if 'item_info' in form:   # temporary hack until things get totally sorted out with 'item_info' (should only need this)
                        print added.get_id()
                    else:
                        print item.get_distributors_str()
                elif action == 'remove':                        # delete distributor item with given distributor name and item name
                    if not db.is_distributor_item(item,dist):
                        raise Exception ('%s is not currently a distributor for %s' % (dist, item))
                    else:
                        db.remove_distributor_item(item,dist)
                        print item.get_distributors_str()
                elif action == 'update':                              # update information (case size/units etc) for a distributor item
                    dist_item = db.get_distributor_item(item,dist)
                    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 'price' in form:
                        wholesale_price = float(form.getvalue('price'))
                    if 'casesize' in form:
                        case_size = float(form.getvalue('casesize'))
                    if 'caseunit' in form:
                        case_unit = form.getvalue('caseunit')            
                        case_unit_id = db.get_unit_byname(case_unit).get_id()

                    db.update_distributor_item(dist_item, dist_item_id, wholesale_price, case_size, case_unit_id)
else:
    raise Exception ('invalid action')
    else:
        raise Exception ('invalid arguments. given %s' % (form.keys()))
elif action == 'item_price':
    if 'item_id' in form and 'price' in form:
        itemid = form.getvalue('item_id')
        if itemid.isdigit():
            item = db.get_item(int(itemid))
            price_items = db.get_items_with_price_id(item.get_price_id())
            if 'confirmed' in form or len(price_items) == 1:
                price = db.get_price(item.get_price_id())
                db.set_price(price, float(form.getvalue("price")))
            else:
                print 'Warning: changing this price will affect the following items:'
                for i in price_items:
                    print '%s. SKU %d' % (i, i.get_id())
        else:
            raise Exception('invalid item_id')
    else:
        raise Exception ('invalid arguments. given %s' % (form.keys()))
elif action == 'sale_unit':
    if "price_id" in form and "unit_name":
        priceid = form.getvalue("price_id")
        price = db.get_price(int(priceid))
        unitname = form.getvalue("unit_name").strip()
        unitid = db.get_unit_byname(unitname).get_id()
        db.set_price_sale_unit_id(price,unitid)
    else:
        raise Exception ('invalid arguments. given %s' % (form.keys()))
else:
    raise Exception ('invalid action')