Esempio n. 1
0
def delete(product_id):
    try:
        product = inventory().get_product(product_id)
    except KeyError:
        return notfound()

    inventory().remove_product(product.id)
    document().save(u'Fjernede "%s"' % (product.name,))
    redirect("product.browse")
Esempio n. 2
0
def create_do():
    name = local.request.form.get("name", u"")
    fixedprice = local.request.form.get("fixedprice", u"")
    if len(fixedprice) == 0:
        fixedprice = None
    else:
        fixedprice = parsenumber(fixedprice)

    product = Product(name=name, fixedprice=fixedprice)
    inventory().add_product(product)

    document().save(u"Tilføjede produkt '%s'" % (product.name, ))

    redirect("product.edit", product_id=product.id)
Esempio n. 3
0
def index():
    cash_in_hand = document().cash_in_hand.get_balance()

    recievable_cash = 0
    for a in accounts().accounts.values():
        b = a.get_balance()
        if b < 0:
            recievable_cash += abs(b)

    income = 0
    expenses = 0
    profit = 0
    for p in inventory().products.values():
        expenses += p.total_purchase()
        income += p.income.get_balance()
        profit += p.profit.get_balance()

    template_response("/page/index.mako",
        comment = document().comment,
        date = document().date,
        income = income,
        expenses = expenses,
        recievable_cash = recievable_cash,
        cash_in_hand = cash_in_hand,
        profit = profit

    )
Esempio n. 4
0
def new_form():
    accounts_list = [(a.id, a.name) for a in accounts().list_by_name()]
    products = [(a.id, a.name, a.get_fixedprice(1)) for a in inventory().list_by_name()]

    template_response("/page/usage/form.mako",
        accounts = accounts_list,
        products = products,
    )
Esempio n. 5
0
def browse():
    products = []
    for a in inventory().list_by_name():
        sold = a.total_quantity() - a.stock if a.stock is not None else 0
        products.append((a.id, a.name, a.total_purchase(), a.fixedprice, a.get_fixedprice(1), a.total_quantity(), sold))

    template_response("/page/product/browse.mako",
        products = products,
    )
Esempio n. 6
0
def purchase_delete(product_id, purchase_id):
    try:
        product = inventory().get_product(product_id)
        purchase = product.get_purchase(purchase_id)
    except KeyError:
        return notfound()

    product.remove_purchase(purchase.id)
    document().save(u'Fjernede indkøb "%s" fra produkt "%s"' % (product.name, purchase.name))
    redirect("product.edit", product_id=product_id)
Esempio n. 7
0
def purchase_do(product_id):
    try:
        product = inventory().get_product(product_id)
    except KeyError:
        return notfound()

    name = local.request.form.get("name", u"")
    quantity = int(local.request.form.get("quantity", u"0"))
    price = parsenumber(local.request.form.get("price", u"0"))

    purchase = Purchase(name, price, quantity)
    product.add_purchase(purchase)

    document().save(u"Tilføjede indkøb '%s' til '%s'" % (name, product.name))
    redirect("product.edit", product_id=product.id)
Esempio n. 8
0
def edit(product_id):
    try:
        product = inventory().get_product(product_id)
    except KeyError:
        return notfound()

    purchases_iter = ((p.name, p.price, p.quantity, p.date, p.id) for p in product.list_purchases_by_date())

    template_response("/page/product/edit.mako",
        id = product.id,
        name = product.name,
        stock = product.stock,
        fixedprice = product.fixedprice,
        purchases = purchases_iter
    )
Esempio n. 9
0
def update_usage_from_form():
    for p in inventory().list_by_name():
        try:
            stock = int(local.request.form.get("stock_%s" % (p.id, ), "0"))
        except:
            stock = 0
        p.stock = stock

        profit = parsenumber(local.request.form.get("profit_%s" % (p.id, ), "0"))

        usage().set_profit(p.id, profit or 0)

        for a in accounts().list_by_name():
            try:
                amount = int(local.request.form.get("usage_%s_%s" % (a.id, p.id), "0"))
            except:
                amount = 0
            usage().update(a.id, p.id, amount)
Esempio n. 10
0
def edit_do(product_id):
    try:
        product = inventory().get_product(product_id)
    except KeyError:
        return notfound()

    name = local.request.form.get("name", u"")
    fixedprice = local.request.form.get("fixedprice", u"")
    if len(fixedprice) == 0:
        fixedprice = None
    else:
        fixedprice = parsenumber(fixedprice)

    product.name = name
    product.fixedprice = fixedprice

    document().save(u"Ændrede data for produkt '%s'" % (name,))

    redirect("product.edit", product_id=product_id)
Esempio n. 11
0
def purchase_form(product_id):
    product = inventory().get_product(product_id)
    template_response("/page/product/purchase_form.mako",
        product_id = product.id,
        product_name = product.name,
    )