Ejemplo n.º 1
0
def display():
    setExits()

    recs = Transfer(g.db).select()

    #Get categories to display
    items = Item(g.db)
    item = {}
    #import pdb;pdb.set_trace()

    if recs:
        for rec in recs:
            fnd = items.get(rec.item_id)
            if fnd:
                item[rec.item_id] = fnd.name

    return render_template('transfer_list.html', recs=recs, item=item)
Ejemplo n.º 2
0
def edit(id=None):
    setExits()
    g.title = "Edit {} Record".format(g.title)

    item = Item(g.db)
    transactionList = None
    #import pdb;pdb.set_trace()
    if request.form:
        id = request.form.get('id', None)

    id = cleanRecordID(id)

    if id < 0:
        flash("Invalid Record ID")
        return redirect(g.listURL)

    categories = Category(g.db).select()
    uoms = Uom(g.db).select()

    if id >= 0 and not request.form:
        if id == 0:
            rec = item.new()  # allow creation of new properties
            item.save(rec)  # need an id for transactions
            g.db.commit()  # have to commit this to protect the ID we just got
            # This name changes behavure of the Cancel link in the edit form
            g.cancelURL = url_for('.cancel') + "{}/".format(rec.id)

        else:
            rec = item.get(id)

        if not rec:
            flash('Record not Found')
            return redirect(g.listURL)

    #import pdb;pdb.set_trace()

    if request.form:
        rec = item.get(id)
        if rec:
            item.update(rec, request.form)
            if validate_form():
                item.save(rec)
                try:
                    g.db.commit()
                    return redirect(g.listURL)

                except Exception as e:
                    g.db.rollback()
                    flash(
                        printException('Error attempting to save Item record',
                                       str(e)))
                    return redirect(g.listURL)
            else:
                pass  # There are imput errors

        else:
            flash('Record not Found')
            return redirect(g.listURL)

    transactionList = get_trx_list_for_item(rec.id)
    transferList = get_transfer_list_for_item(rec.id)
    qoh_list = get_qoh_by_warehouse(rec.id)
    on_hand = item.stock_on_hand(id)

    return render_template('item_edit.html',
                           rec=rec,
                           categories=categories,
                           uoms=uoms,
                           transactionList=transactionList,
                           transferList=transferList,
                           qoh_list=qoh_list,
                           on_hand=on_hand)