def category_new(workspace): form = CategoryForm() if form.validate_on_submit(): category = Category(workspace=workspace) form.populate_obj(category) category.make_name() db.session.add(category) db.session.commit() flash("Created new category in workspace '%s'." % workspace.name, "success") return render_redirect(url_for('category_list', workspace=workspace.name), code=303) return render_form(form=form, title=u"Create new category", formid="category_new", submit=u"Create", cancel_url=url_for('category_list', workspace=workspace.name), ajax=False)
def invoice(workspace, invoice): workflow = invoice.workflow() if not workflow.can_view(): abort(403) lineitemform = LineItemForm() lineitemform.category.choices = [(c.id, c.title) for c in Category.get_by_status(workspace, CATEGORY_STATUS.LIVE)] lineitemform.invoice = invoice if lineitemform.validate_on_submit(): if lineitemform.id.data: lineitem = LineItem.query.get(lineitemform.id.data) else: lineitem = LineItem() db.session.add(lineitem) lineitem.invoice_id = lineitemform.invoice.id lineitem.category_id = lineitemform.category.data category = Category.get_by_id(workspace, lineitem.category_id).first() lineitem.description = category.title lineitem.tax_rate = category.tax_rate lineitem.pat = category.pat lineitem.quantity = lineitemform.quantity.data db.session.commit() lineitem.update_total() invoice.update_total() db.session.commit() if request.is_xhr: lineitemform = LineItemForm(MultiDict()) lineitemform.category.choices = [(c.id, c.title) for c in Category.get_by_status(workspace, CATEGORY_STATUS.LIVE)] return render_template("lineitem.html.jinja2", workspace=workspace, invoice=invoice.url_name, lineitemform=lineitemform) else: return redirect(url_for('invoice', workspace=workspace.name, invoice=invoice.url_name, lineitemform=lineitemform), code=303) if request.is_xhr: return render_template("lineitem.html.jinja2", workspace=workspace, invoice=invoice, lineitemform=lineitemform) return render_template('invoice.html.jinja2', workspace=workspace, invoice=invoice, lineitemform=lineitemform, workflow=workflow, transitions=workflow.transitions())
def sidebarvars(): if hasattr(g, "user"): # More access control? org_ids = g.user.organizations_memberof_ids() else: org_ids = [] workspaces = Workspace.query.filter(Workspace.userid.in_(org_ids)).order_by("title").all() if hasattr(g, "workspace"): return { "workspaces": workspaces, "categories": Category.get(g.workspace).order_by("title").all(), "invoice_states": InvoiceWorkflow.states(), "permissions": lastuser.permissions(), } else: return {"workspaces": workspaces}
def sidebarvars(): if hasattr(g, 'user') and g.user: # More access control? org_ids = g.user.organizations_memberof_ids() else: org_ids = [] workspaces = Workspace.query.filter(Workspace.userid.in_(org_ids)).order_by('title').all() if hasattr(g, 'workspace'): return { 'workspaces': workspaces, 'categories': Category.get(g.workspace).order_by('title').all(), 'invoice_states': InvoiceWorkflow.states(), 'permissions': lastuser.permissions() } else: return { 'workspaces': workspaces, }
def category_list(workspace): categories = Category.get(workspace) return render_template('categories.html', categories=categories)