Skip to content

fix: convert last_performed_odometer to km before storing on maintenance schedules#231

Open
andrew-demers wants to merge 1 commit into
dannymcc:devfrom
andrew-demers:fix-maintenance-mileage-unit-conversion
Open

fix: convert last_performed_odometer to km before storing on maintenance schedules#231
andrew-demers wants to merge 1 commit into
dannymcc:devfrom
andrew-demers:fix-maintenance-mileage-unit-conversion

Conversation

@andrew-demers

@andrew-demers andrew-demers commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Maintenance schedules stored last_performed_odometer as a raw form value without unit conversion, while MaintenanceSchedule.calculate_next_due() assumes km-based storage (it adds interval_miles * 1.60934 directly to last_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 incorrect next_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

  • Fixed: last_performed_odometer is now converted to km (the app's internal odometer convention) before being stored, based on the vehicle's effective odometer unit — in new(), edit(), and complete() in app/routes/maintenance.py.
  • Fixed: next_due_odometer is 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.
  • Fixed: the maintenance edit form now converts the stored km value back to the vehicle's display unit when pre-filling the odometer field, and shows the unit in the field label.

Testing

  • Tested locally
  • Tested with Docker image

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.

…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.
@andrew-demers andrew-demers force-pushed the fix-maintenance-mileage-unit-conversion branch from ea6ed8d to 7be25fc Compare July 7, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant