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