-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Added invoice overview page (#222)
* nf-feat: Started working on tabs * nf-feat: Started working on tabs * Added more control options for invoice overview * Ran formatters * Added option in dropdown
- Loading branch information
Showing
17 changed files
with
983 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from dataclasses import dataclass | ||
from typing import Literal, TypedDict | ||
|
||
from django.contrib import messages | ||
from django.http import HttpRequest | ||
from django.shortcuts import render, redirect | ||
from django.views.decorators.http import require_http_methods | ||
|
||
from backend.models import Invoice, UserSettings | ||
|
||
|
||
class PreviewContext(TypedDict): | ||
type: Literal["preview"] | ||
invoice: Invoice | ||
currency_symbol: str | ||
|
||
|
||
@dataclass(frozen=True) | ||
class SuccessResponse: | ||
context: PreviewContext | ||
success: Literal[True] = True | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ErrorResponse: | ||
message: str | ||
success: Literal[False] = False | ||
|
||
|
||
@require_http_methods(["GET"]) | ||
def tab_preview_invoice(request: HttpRequest, invoice_id): | ||
# Redirect if not an HTMX request | ||
if not request.htmx: | ||
return redirect("invoices dashboard") # Maybe should be 404? | ||
|
||
prev_invoice = preview_invoice(request, invoice_id) | ||
|
||
if prev_invoice.success: | ||
return render(request, "pages/invoices/view/invoice.html", prev_invoice.context) | ||
|
||
messages.error(request, prev_invoice.message) | ||
|
||
return render(request, "base/toasts.html") | ||
|
||
|
||
def preview_invoice(request: HttpRequest, invoice_id) -> SuccessResponse | ErrorResponse: | ||
context = {"type": "preview"} | ||
|
||
try: | ||
invoice = Invoice.objects.prefetch_related("items").get(id=invoice_id) | ||
|
||
except Invoice.DoesNotExist: | ||
return ErrorResponse("Invoice not found") | ||
|
||
if request.user.logged_in_as_team: | ||
if invoice.organization != request.user.logged_in_as_team: | ||
return ErrorResponse("You don't have access to this invoice") | ||
else: | ||
if invoice.user != request.user: | ||
return ErrorResponse("You don't have access to this invoice") | ||
try: | ||
currency_symbol = request.user.user_profile.get_currency_symbol | ||
except UserSettings.DoesNotExist: | ||
currency_symbol = "$" | ||
|
||
context.update({"invoice": invoice, "currency_symbol": currency_symbol}) | ||
|
||
context_object = PreviewContext( | ||
type="preview", | ||
invoice=invoice, | ||
currency_symbol=currency_symbol, | ||
) | ||
|
||
return SuccessResponse(context=context_object) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.http import HttpRequest | ||
|
||
from backend.decorators import * | ||
from backend.models import * | ||
|
||
|
||
def invoices_dashboard(request: HttpRequest): | ||
context = {} | ||
|
||
return render(request, "pages/invoices/dashboard/dashboard.html", context) | ||
|
||
|
||
def manage_invoice(request: HttpRequest, invoice_id: str): | ||
if not invoice_id.isnumeric(): | ||
messages.error(request, "Invalid invoice ID") | ||
return redirect("invoices:dashboard") | ||
|
||
invoice = Invoice.objects.get(id=invoice_id) | ||
|
||
if not invoice: | ||
return redirect("invoices:dashboard") | ||
return render(request, "pages/invoices/dashboard/manage.html", {"invoice": invoice}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.