From 64bffe9639eaa2a6836ce5ba2f3ebd486e1e7a0b Mon Sep 17 00:00:00 2001 From: Devender Butani Date: Tue, 30 Apr 2024 10:27:02 -0400 Subject: [PATCH] Changes in Invoices --- backend/views/core/invoices/dashboard.py | 3 +- backend/views/core/invoices/edit.py | 41 +++++++++++--------- backend/views/core/invoices/manage_access.py | 3 ++ backend/views/core/invoices/overview.py | 7 ++-- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/backend/views/core/invoices/dashboard.py b/backend/views/core/invoices/dashboard.py index 8d8c0f27..96aa3274 100644 --- a/backend/views/core/invoices/dashboard.py +++ b/backend/views/core/invoices/dashboard.py @@ -15,7 +15,7 @@ def invoices_dashboard_id(request: HtmxHttpRequest, invoice_id): if invoice_id == "create": return redirect("invoices:create") - elif not isinstance(invoice_id, int): + elif not invoice_id.isdigit(): messages.error(request, "Invalid invoice ID") return redirect("invoices:dashboard") @@ -23,4 +23,5 @@ def invoices_dashboard_id(request: HtmxHttpRequest, invoice_id): Invoice.objects.get(id=invoice_id) except Invoice.DoesNotExist: return redirect("invoices:dashboard") + return render(request, "pages/invoices/dashboard/dashboard.html", context) diff --git a/backend/views/core/invoices/edit.py b/backend/views/core/invoices/edit.py index 6ba8cab3..befe045a 100644 --- a/backend/views/core/invoices/edit.py +++ b/backend/views/core/invoices/edit.py @@ -29,26 +29,29 @@ def invoice_get_existing_data(invoice_obj): "currency_symbol": invoice_obj.get_currency_symbol(), "rows": invoice_obj.items.all(), } - if invoice_obj.client_to: - stored_data["to_name"] = invoice_obj.client_to.name - stored_data["to_company"] = invoice_obj.client_to.company - stored_data["is_representative"] = invoice_obj.client_to.is_representative - # stored_data["to_address"] = invoice_obj.client_to.address - # stored_data["to_city"] = invoice_obj.client_to.city - # stored_data["to_county"] = invoice_obj.client_to.county - # stored_data["to_country"] = invoice_obj.client_to.country - else: - stored_data["to_name"] = invoice_obj.client_name - stored_data["to_company"] = invoice_obj.client_company - stored_data["to_address"] = invoice_obj.client_address - stored_data["to_city"] = invoice_obj.client_city - stored_data["to_county"] = invoice_obj.client_county - stored_data["to_country"] = invoice_obj.client_country - stored_data["is_representative"] = invoice_obj.client_is_representative - - if invoice_obj.client_to: - stored_data["existing_client"] = invoice_obj.client_to + client_to = invoice_obj.client_to + if client_to: + stored_data.update({ + "to_name": client_to.name, + "to_company": client_to.company, + "is_represntative": client_to.representative, + # "to_address": client_to.address, + # "to_city": client_to.city, + # "to_county": client_to.county, + # "to_country": client_to.country + "existing_client": client_to, + }) + else: + stored_data.update({ + "to_name": invoice_obj.client_name, + "to_company": invoice_obj.client_company, + "to_address": invoice_obj.client_address, + "to_city": invoice_obj.client_city, + "to_county": invoice_obj.client_county, + "to_country": invoice_obj.client_country, + "is_representative": invoice_obj.client_is_representative, + }) return stored_data diff --git a/backend/views/core/invoices/manage_access.py b/backend/views/core/invoices/manage_access.py index 22e20a05..713c8499 100644 --- a/backend/views/core/invoices/manage_access.py +++ b/backend/views/core/invoices/manage_access.py @@ -7,6 +7,7 @@ from backend.types.htmx import HtmxHttpRequest +# Function to manage access codes for an invoice def manage_access(request: HtmxHttpRequest, invoice_id): try: invoice = Invoice.objects.prefetch_related("invoice_urls").get(id=invoice_id, user=request.user) @@ -23,6 +24,7 @@ def manage_access(request: HtmxHttpRequest, invoice_id): ) +# Function to create a new access code for an invoice @quota_usage_check("invoices-access_codes", 1, api=True, htmx=True) def create_code(request: HtmxHttpRequest, invoice_id): if not request.htmx: @@ -49,6 +51,7 @@ def create_code(request: HtmxHttpRequest, invoice_id): ) +#Function to delete an access code for an invoice def delete_code(request: HtmxHttpRequest, code): if request.method != "DELETE" or not request.htmx: return HttpResponse("Request invalid", status=400) diff --git a/backend/views/core/invoices/overview.py b/backend/views/core/invoices/overview.py index 41b9eb16..a4c35963 100644 --- a/backend/views/core/invoices/overview.py +++ b/backend/views/core/invoices/overview.py @@ -14,9 +14,10 @@ def manage_invoice(request: HtmxHttpRequest, invoice_id: str): messages.error(request, "Invalid invoice ID") return redirect("invoices:dashboard") - invoice = Invoice.objects.get(id=invoice_id) - - if not invoice: + try: + invoice = Invoice.objects.get(id=invoice_id) + except Invoice.DoesNotExist: + messages.error(request, "Invoice not found") return redirect("invoices:dashboard") print(context | {"invoice": invoice})