Skip to content

Commit

Permalink
Changes in Invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
devenderbutani21 committed Apr 30, 2024
1 parent a2bb725 commit 64bffe9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
3 changes: 2 additions & 1 deletion backend/views/core/invoices/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ 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")

try:
Invoice.objects.get(id=invoice_id)
except Invoice.DoesNotExist:
return redirect("invoices:dashboard")

return render(request, "pages/invoices/dashboard/dashboard.html", context)
41 changes: 22 additions & 19 deletions backend/views/core/invoices/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 3 additions & 0 deletions backend/views/core/invoices/manage_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions backend/views/core/invoices/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 64bffe9

Please sign in to comment.