Skip to content

Commit

Permalink
fix: init meter with no entries
Browse files Browse the repository at this point in the history
If there were no entries the code didn't fetch the meter stats from the
vehicle objects, now it does :)
  • Loading branch information
sgronlund committed Sep 25, 2024
1 parent 7b16fc7 commit 2ae2ea0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/bocken/forms/journal_entry_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ def __init__(self, *args, **kwargs):
# their latest trip to automatically set as a value for when
# a user is registering a new journal entry
for item in latest_entries:
self.initial[f'meter_start_{str(item.vehicle.id).lower()}'] = item.meter_stop

print(f"{str(item.vehicle.id)}")
print(f"{str(item.vehicle.id).lower()}")
self.initial[f'meter_start_{str(item.vehicle.id)}'] = item.meter_stop
else:
#if there is not a latest entry, then fetch from vehicle objects
#ideally it should always be fetched from here but..?
for vehicle in all_vehicles:
self.initial[f'meter_start_{str(vehicle.id)}'] = vehicle.vehicle_meter_stop
# If there is data from the previous form (a.k.a. invalid data
# was passed) we need to add some of that data to the TwoLevelSelect
# widget so that it can automatically choose a default option.
Expand Down
4 changes: 0 additions & 4 deletions src/bocken/templates/journalentry_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
{{field}}
{% elif field == form.meter_start %}
<div class="flex items-center relative font-thin font-sans text-gray-400 {% if field.errors %}border-red-600{% else %}border-gray-100{% endif %} border-solid border-2"
{#%
Following templates iterates over the initial items and stores them as an attribute for this container.
These values are then used to dynamically set the last meter_stop in the form based on the vehicle choosen
%#}
{% for value,name in form.initial.items %}
{{value}}={{name}}
{% endfor %}
Expand Down

0 comments on commit 2ae2ea0

Please sign in to comment.