Skip to content

Commit

Permalink
fixed multiple bugs with editing invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyWW committed Nov 15, 2024
1 parent 40c57b0 commit 849ed79
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion backend/core/service/invoices/common/create/services/add.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.http import JsonResponse

from backend.core.api.public.types import APIRequest
from backend.core.types.requests import WebRequest
from backend.finance.models import InvoiceProduct
from backend.core.types.htmx import HtmxHttpRequest


def add(request: APIRequest | HtmxHttpRequest):
def add(request: APIRequest | WebRequest):
context: dict = {}
existing_service = request.POST.get("existing_service", 0)

Expand Down
4 changes: 2 additions & 2 deletions backend/finance/api/invoices/create/services/add_service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.shortcuts import render
from django.views.decorators.http import require_http_methods

from backend.core.types.htmx import HtmxHttpRequest
from backend.core.service.invoices.common.create.services.add import add
from backend.core.types.requests import WebRequest


@require_http_methods(["POST"])
def add_service_endpoint(request: HtmxHttpRequest):
def add_service_endpoint(request: WebRequest):
return render(request, "pages/invoices/create/services/_services_table_body.html", add(request))
3 changes: 2 additions & 1 deletion backend/finance/api/invoices/create/set_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from django.shortcuts import render
from django.views.decorators.http import require_http_methods

from backend.core.types.requests import WebRequest
from backend.models import Client
from backend.core.types.htmx import HtmxHttpRequest

to_get = ["name", "address", "city", "country", "company", "is_representative", "email"]


@require_http_methods(["POST"])
def set_destination_to(request: HtmxHttpRequest):
def set_destination_to(request: WebRequest):
context: dict = {"swapping": True}

context.update({f"to_{key}": request.POST.get(key, "") for key in to_get})
Expand Down
10 changes: 5 additions & 5 deletions backend/finance/views/invoices/single/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def edit_invoice(request: WebRequest, invoice_id):
"reference": request.POST.get("reference"),
"sort_code": request.POST.get("sort_code"),
"account_number": request.POST.get("account_number"),
"account_holder_name": request.POST.get("account_holder_name")
"account_holder_name": request.POST.get("account_holder_name"),
}

client_to_id = request.POST.get("selected_client")
Expand All @@ -127,7 +127,7 @@ def edit_invoice(request: WebRequest, invoice_id):

if client_to_obj:
invoice.client_to = client_to_obj

for att in client_attrs.keys():
setattr(invoice, att, None)
else:
Expand All @@ -140,8 +140,8 @@ def edit_invoice(request: WebRequest, invoice_id):
"client_city": request.POST.get("to_city"),
"client_county": request.POST.get("to_county"),
"client_country": request.POST.get("to_country"),
"client_is_representative": True if request.POST.get("is_representative") == "on" else False,
"client_to": None
"client_is_representative": True if request.POST.get("is_representative") == "on" else False, # type: ignore[dict-item]
"client_to": None,
}
)

Expand Down Expand Up @@ -174,7 +174,7 @@ def edit_invoice(request: WebRequest, invoice_id):
# decorator & view function for rendering page and updating invoice items in the backend
@require_http_methods(["GET", "POST"])
@web_require_scopes("invoices:write", False, False, "finance:invoices:single:dashboard")
def edit_invoice_page(request: HtmxHttpRequest, invoice_id):
def edit_invoice_page(request: WebRequest, invoice_id):
if request.method == "POST":
return edit_invoice(request, invoice_id)
return invoice_edit_page_get(request, invoice_id)
3 changes: 2 additions & 1 deletion frontend/templates/modals/invoices_to_destination.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
Single
<input type="checkbox"
name="is_representative"
class="toggle toggle-primary" {% if is_representative %}checked{% endif %}/>
class="toggle toggle-primary"
{% if is_representative %}checked{% endif %} />
Representative
</label>
</div>
Expand Down

0 comments on commit 849ed79

Please sign in to comment.