@@ -76,7 +76,7 @@ def edit_invoice_endpoint(request: APIRequest):
76
76
77
77
@api_view (["POST" ])
78
78
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 ""
80
80
81
81
try :
82
82
invoice = Invoice .objects .get (id = invoice_id )
@@ -86,15 +86,13 @@ def change_status_endpoint(request, invoice_id: int, invoice_status: str):
86
86
if request .user .logged_in_as_team and request .user .logged_in_as_team != invoice .organization or request .user != invoice .user :
87
87
return APIResponse (False , {"error" : "You do not have permission to edit this invoice" }, status = status .HTTP_403_FORBIDDEN )
88
88
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 )
91
91
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 )
94
94
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 )
98
96
99
97
100
98
@api_view (["POST" ])
0 commit comments