Exemple #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")
Exemple #2
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)
Exemple #3
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)
Exemple #4
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
    )
Exemple #5
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)