Exemple #1
0
def invoice_edit_internal(workspace, form, invoice=None, workflow=None):
    if form.validate_on_submit():
        if invoice is None:
            invoice = Invoice(workspace=workspace)
            invoice.user = g.user
        form.populate_obj(invoice)
        invoice.make_name()
        db.session.add(invoice)
        db.session.commit()
        flash("Created new invoice '%s'." % invoice.title, "success")
        return redirect(url_for('invoice', workspace=workspace.name, invoice=invoice.url_name), code=303)
    return render_template('invoice_new.html.jinja2',
        workspace=workspace, form=form, invoice=invoice, workflow=workflow)
Exemple #2
0
def prepare_invoice(workspace_name, lineitems, title):
    workspace = Workspace.get(workspace_name)
    if lineitems is None:
        return jsonify({'error': 'No line items specified'})

    invoice = Invoice(workspace=workspace, user=g.user, status=INVOICE_STATUS.ESTIMATE)
    invoice.title = title
    invoice.make_name()
    invoice.addressee = invoice.user.fullname
    db.session.commit()
    for idx, l in enumerate(lineitems):
        lineitem = LineItem()
        db.session.add(lineitem)

        lineitem.invoice_id = invoice.id
        lineitem.category_id = l.get('category_id', None)
        lineitem.description = l.get('event', None) + ' ' + l.get('category_desc', None)
        lineitem.tax_rate = l.get('tax_rate', None)
        lineitem.pat = l.get('pat', None)
        lineitem.quantity = l.get('quantity', None)
        db.session.commit()

        lineitem.update_total()
        invoice.update_total()
        db.session.commit()
    return jsonify(
        invoice=invoice.url_name,
        url=app.config['SITE_URL'] + url_for('select_address',
        workspace=workspace.name,
        invoice=invoice.url_name))
Exemple #3
0
def available_invoices(workspace, user=None):
    if user is None:
        user = g.user
    query = Invoice.getw(workspace)
    # FIXME+TODO: Replace with per-workspace permissions
    if 'reviewer' in lastuser.permissions():
        # Get all invoices owned by this user and in states where the user can review them
        query = query.filter(db.or_(
            Invoice.user == user, Invoice.status.in_(InvoiceWorkflow.reviewable.values)))
    else:
        query = query.filter_by(user=user)
    return query