Esempio n. 1
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. 2
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. 3
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. 4
0
def enter_title_do():
    title = local.request.form.get("title", u"")

    if len(title) == 0:
        return redirect("misc.enter_title_form")

    document().title = title
    document().save(u'Ændrede titel til "%s"' % (title,))

    redirect("index.index")
Esempio n. 5
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. 6
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. 7
0
    def dispatch(self, environ, start_response):
        try:
            local.request = Request(environ)
            local.response = Response()
            local.session = Session(local.request.cookies.get("session"))
            try:
                local.url_adapter = url_adapter = url_map.bind_to_environ(environ)
                try:
                    endpoint, params = url_adapter.match()
                except NotFound:
                    endpoint = "notfound"
                    params = {}

                if not endpoint in ("notfound", "misc.enter_title_do") and document().title == None:
                    endpoint = "misc.enter_title_form"

                local.endpoint = endpoint

                endpoints[endpoint](**params)
            except:
                if self.debug:
                    raise
                endpoints["error"]()
            response = local.response
            local.session.set_cookie(local.response)
        except:
            if self.debug:
                raise
            response = Response("Fejlsidens fejlside.")

        return response(environ, start_response)
Esempio n. 8
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. 9
0
def adjust_cash():
    amount = parsenumber(local.request.form.get("amount", u""))

    if amount != None and amount != 0:
        document().cash_in_hand.add_transaction("Justerede kassebeholdning", amount)

        amount_str = formatcurrency(abs(amount))
        if amount < 0:
            document().save("Tog %s fra kassen." % (amount_str,))
        else:
            document().save("Lagde %s i kassen." % (amount_str,))
    redirect("misc.cashlog")
Esempio n. 10
0
def new_form_do():
    update_usage_from_form()
    usage().commit()
    document().save(u"Afregning")

    redirect("account.browse")
Esempio n. 11
0
def doc_title():
    return document().title
Esempio n. 12
0
def cashlog():
    log = ((t.date, t.description, t.amount) for t in document().cash_in_hand.transactions)
    template_response("/page/cash_log.mako",
        log = log,
        balance = document().cash_in_hand.get_balance()
    )