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))
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)