Skip to content

Commit dac7ff8

Browse files
committed
fixed mypy types
1 parent 2078f72 commit dac7ff8

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

backend/core/api/public/endpoints/Invoices/edit.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def edit_invoice_endpoint(request: APIRequest):
7676

7777
@api_view(["POST"])
7878
def change_status_endpoint(request, invoice_id: int, invoice_status: str):
79-
invoice_status: Literal["paid", "draft", "pending"] = invoice_status.lower() if invoice_status else ""
79+
new_status = invoice_status.lower() if invoice_status else ""
8080

8181
try:
8282
invoice = Invoice.objects.get(id=invoice_id)
@@ -86,15 +86,13 @@ def change_status_endpoint(request, invoice_id: int, invoice_status: str):
8686
if request.user.logged_in_as_team and request.user.logged_in_as_team != invoice.organization or request.user != invoice.user:
8787
return APIResponse(False, {"error": "You do not have permission to edit this invoice"}, status=status.HTTP_403_FORBIDDEN)
8888

89-
if invoice_status not in ["paid", "draft", "pending"]:
90-
return APIResponse(False, {"error": "Invalid status. Please choose from: pending, paid, draft"}, status=status.HTTP_400_BAD_REQUEST)
89+
if invoice.status == new_status:
90+
return APIResponse(False, {"error": f"Invoice status is already {new_status}"}, status=status.HTTP_400_BAD_REQUEST)
9191

92-
if invoice.status == invoice_status:
93-
return APIResponse(False, {"error": f"Invoice status is already {invoice_status}"}, status=status.HTTP_400_BAD_REQUEST)
92+
if not invoice.set_status(new_status, save=True):
93+
return APIResponse(False, {"error": "Invalid status. Please choose from: pending, paid, draft"}, status=status.HTTP_400_BAD_REQUEST)
9494

95-
invoice.set_status(invoice_status)
96-
97-
return APIResponse(True, {"message": f"Invoice status been changed to <strong>{invoice_status}</strong>"}, status=status.HTTP_200_OK)
95+
return APIResponse(True, {"message": f"Invoice status been changed to <strong>{new_status}</strong>"}, status=status.HTTP_200_OK)
9896

9997

10098
@api_view(["POST"])

backend/finance/api/invoices/edit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def edit_invoice(request: HtmxHttpRequest):
7777
@require_POST
7878
@web_require_scopes("invoices:write", True, True)
7979
def change_status(request: HtmxHttpRequest, invoice_id: int, status: str) -> HttpResponse:
80-
status: Literal["paid", "draft", "pending"] = status.lower() if status else ""
80+
status = status.lower() if status else ""
8181

8282
if not request.htmx:
8383
return redirect("finance:invoices:single:dashboard")

backend/finance/api/invoices/recurring/update_status.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Literal
12
from django.conf import settings
23
from django.contrib import messages
34
from django.http import HttpRequest, HttpResponse

backend/finance/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ def __str__(self):
169169

170170
return f"Invoice #{invoice_id} for {client}"
171171

172-
def set_status(self, status: Literal["draft", "pending", "paid"], save=True):
172+
def set_status(self, status: str, save=True):
173+
if status not in ["draft", "pending", "paid"]:
174+
return False
173175
self.status = status
174176
self.status_updated_at = timezone.now()
175177
if save:

0 commit comments

Comments
 (0)