예제 #1
0
def expenses_history(request):
    """Display expense history.
    @param year: year of history. If None, display recent items and year index"""
    expenses = Expense.objects.all().select_related().prefetch_related(
        "clientbill_set", "user", "lead")
    try:
        consultant = Consultant.objects.get(
            trigramme__iexact=request.user.username)
        user_team = consultant.userTeam()
    except Consultant.DoesNotExist:
        user_team = []

    if not perm.has_role(request.user, "expense paymaster"):
        expenses = expenses.filter(
            Q(user=request.user) | Q(user__in=user_team))

    expenseTable = ExpenseTable(expenses, orderable=True)
    RequestConfig(request, paginate={"per_page": 50}).configure(expenseTable)

    if "csv" in request.GET:
        return tableToCSV(expenseTable, filename="expenses.csv")

    return render(request, "expense/expense_archive.html", {
        "expense_table": expenseTable,
        "user": request.user
    })
예제 #2
0
def lead_expenses(request, lead_id):
    """Page fragment or csv that display expenses related to given lead"""
    try:
        lead = Lead.objects.get(id=lead_id)
        expenses = Expense.objects.filter(lead=lead).select_related().prefetch_related("clientbill_set")
    except Lead.DoesNotExist:
        expenses = []
    if "csv" in request.GET:
        expenseTable = ExpenseTable(expenses, orderable=True)
        RequestConfig(request, paginate={"per_page": 50}).configure(expenseTable)
        return tableToCSV(expenseTable, filename="expenses.csv")
    return render(request, "expense/expense_list.html",
                  {"expenses": expenses,
                   "lead": lead,
                   "user": request.user})
예제 #3
0
파일: views.py 프로젝트: digitalfox/pydici
def lead_expenses(request, lead_id):
    """Page fragment or csv that display expenses related to given lead"""
    try:
        lead = Lead.objects.get(id=lead_id)
        expenses = Expense.objects.filter(lead=lead).select_related().prefetch_related("clientbill_set")
    except Lead.DoesNotExist:
        expenses = []
    if "csv" in request.GET:
        expenseTable = ExpenseTable(expenses, orderable=True)
        RequestConfig(request, paginate={"per_page": 50}).configure(expenseTable)
        return tableToCSV(expenseTable, filename="expenses.csv")
    return render(request, "expense/expense_list.html",
                  {"expenses": expenses,
                   "lead": lead,
                   "user": request.user})
예제 #4
0
파일: views.py 프로젝트: digitalfox/pydici
def expenses_history(request):
    """Display expense history.
    @param year: year of history. If None, display recent items and year index"""
    expenses = Expense.objects.all().select_related().prefetch_related("clientbill_set", "user", "lead")
    try:
        consultant = Consultant.objects.get(trigramme__iexact=request.user.username)
        user_team = consultant.userTeam()
    except Consultant.DoesNotExist:
        user_team = []

    if not utils.has_role(request.user, "expense paymaster"):
        expenses = expenses.filter(Q(user=request.user) | Q(user__in=user_team))

    expenseTable = ExpenseTable(expenses, orderable=True)
    RequestConfig(request, paginate={"per_page": 50}).configure(expenseTable)

    if "csv" in request.GET:
        return tableToCSV(expenseTable, filename="expenses.csv")

    return render(request, "expense/expense_archive.html", {"expense_table": expenseTable, "user": request.user})