fix: convert last_performed_odometer to km before storing on maintenance schedules#231
Open
andrew-demers wants to merge 1 commit into
Open
Conversation
…nce schedules MaintenanceSchedule.calculate_next_due() assumes km-based storage for last_performed_odometer, but new(), edit(), and complete() stored the raw form value with no unit conversion. For mi-unit vehicles this meant the interval was converted to km and added to a value still in miles, producing a wildly incorrect next_due_odometer. Also convert next_due_odometer back to the vehicle's display unit wherever it's rendered, and convert last_performed_odometer back when pre-filling the edit form, so the fix doesn't introduce a display-side unit mismatch.
ea6ed8d to
7be25fc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Maintenance schedules stored
last_performed_odometeras a raw form value without unit conversion, whileMaintenanceSchedule.calculate_next_due()assumes km-based storage (it addsinterval_miles * 1.60934directly tolast_performed_odometer). For vehicles set to miles, this meant the interval was converted to km and added to a value that was still in miles, producing a wildly incorrectnext_due_odometer.Example: a vehicle at 29,711 mi with a 5,000 mi service interval should show the next service due at 34,711 mi. It previously showed ~37,758 mi.
Changelog
last_performed_odometeris now converted to km (the app's internal odometer convention) before being stored, based on the vehicle's effective odometer unit — innew(),edit(), andcomplete()inapp/routes/maintenance.py.next_due_odometeris now converted back to the vehicle's display unit wherever it's rendered (maintenance/index.html,vehicles/view.html), instead of showing the raw km value labeled with the wrong unit.Testing
Verified with the reported repro case: a mi-unit vehicle with
last_performed_odometer= 29,711 mi and a 5,000 mi interval now correctly shows the next service due at 34,711 mi.