Skip to content

Commit

Permalink
232: Details dont get pre-filled using the "Update FROM info" modal o…
Browse files Browse the repository at this point in the history
…n EDIT (#273)

- pre-populate invoice from info on editing
  • Loading branch information
introkun authored Apr 2, 2024
1 parent 4f4b706 commit 9650fce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
13 changes: 13 additions & 0 deletions backend/api/base/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ def open_modal(request: HttpRequest, modal_name, context_type=None, context_valu
# context["to_city"] = invoice.client_city
# context["to_county"] = invoice.client_county
# context["to_country"] = invoice.client_country
elif context_type == "edit_invoice_from":
invoice = context_value
try:
invoice = Invoice.objects.get(user=request.user, id=invoice)
except Invoice.DoesNotExist:
return render(request, template_name, context)

context["from_name"] = invoice.self_name
context["from_company"] = invoice.self_company
context["from_address"] = invoice.self_address
context["from_city"] = invoice.self_city
context["from_county"] = invoice.self_county
context["from_country"] = invoice.self_country
elif context_type == "invoice":
try:
invoice = Invoice.objects.get(id=context_value)
Expand Down
12 changes: 6 additions & 6 deletions frontend/templates/modals/invoices_from_destination.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@
<input type="text"
name="name"
placeholder="John Smith"
value=""
value="{{ from_name }}"
class="input input-bordered max-w-full">
</div>
<div class="form-control">
<label class="label">Company</label>
<input type="text"
name="company"
placeholder="Google"
value=""
value="{{ from_company }}"
class="input input-bordered max-w-full">
</div>
<div class="form-control">
<label class="label">Address</label>
<input type="text"
name="address"
placeholder="128 Road"
value=""
value="{{ from_address }}"
class="input input-bordered max-w-full">
</div>
<div class="form-control">
<label class="label">City</label>
<input type="text"
name="city"
placeholder="Oxford"
value=""
value="{{ from_city }}"
class="input input-bordered max-w-full">
</div>
<div class="form-control">
<label class="label">County</label>
<input type="text"
name="county"
placeholder="Oxfordshire"
value=""
value="{{ from_county }}"
class="input input-bordered max-w-full">
</div>
<div class="form-control">
<label class="label">Country</label>
<input type="text"
name="country"
placeholder="England"
value=""
value="{{ from_country }}"
class="input input-bordered max-w-full">
</div>
<div class="modal-action">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
hx-trigger="click once"
hx-swap="beforeend"
hx-target="#modal_container"
hx-get="{% url "api:base:modal retrieve" modal_name="invoices_from_destination" %}">
hx-get="{% url 'api:base:modal retrieve with context' modal_name='invoices_from_destination' context_type='edit_invoice_from' context_value=invoice_object.id %}">
{% endif %}
<!-- *Need to replace the default values with attributes from data_to_populate dict* -->
<!-- PRE-POPULATE FIELDS WITH EXISTING DATA OF THE INVOICE-->
Expand Down

0 comments on commit 9650fce

Please sign in to comment.