Case study · Python

Repair a Booking Ledger and Occupancy Report

Repair a versioned booking ledger and its nightly occupancy report.

The situation

A rental marketplace has moved from properties to individual units. The nightly report now double-counts cancelled bookings and multiplies revenue when capacity changes. Repair the loader and report without discarding booking history.

Report grain

+------------------------------+-------------------------------+
|                         Input|              Expected behavior|
+------------------------------+-------------------------------+
|B2 v1 confirmed / v2 cancelled|              No occupied night|
|    U1 capacity 2 → 3 on Nov 2|Use the date-effective capacity|
+------------------------------+-------------------------------+

Your task

Load each booking version once. Reject conflicting replays, unknown units, currency mismatches, and overlapping current confirmed stays; a failed batch must leave no partial changes.

Report occupied unit nights, revenue in integer cents, and effective-dated property capacity. Use the latest booking version before filtering cancellations. Keep currencies separate.

Split revenue across nights, assigning leftover cents to the earliest nights. Sketch the property → unit → booking relationship and note how the unit-level model changes the report grain.

Review the lesson
Sources & interview context

Original CodeBaobab case inspired by candidate-reported interview patterns. All repository files, fixtures, defects, and tests are authored here; they are not company interview materials.