Skip to content

[16.0][FIX] pms: validate reservation dates once both are computed - #445

Merged
OCA-git-bot merged 1 commit into
OCA:16.0from
DarioLodeiros:16.0-fix-reservation-checkin-checkout-validation
Sep 7, 2026
Merged

[16.0][FIX] pms: validate reservation dates once both are computed#445
OCA-git-bot merged 1 commit into
OCA:16.0from
DarioLodeiros:16.0-fix-reservation-checkin-checkout-validation

Conversation

@DarioLodeiros

Copy link
Copy Markdown
Member

Problem

check_in_out_dates() was called from inside _compute_checkin, _compute_checkout and _compute_reservation_line_ids, so it validated the checkin/checkout pair while it was still being computed.

A reservation created without dates defaults its checkin to the one of the first reservation of its folio. When the same write also supplies reservation_line_ids, that default is only replaced once the lines are stored, so a reservation of the batch can still be holding the inherited checkin while its checkout has already been computed from its own lines. Adding to a folio several reservations whose dates are earlier than the ones already in it then fails with:

Room line Check In Date Should be less than the Check Out Date!

even though the values being stored are consistent.

The shape that triggers it in production is a channel-manager modification that brings a multi-room stay forward. The folio holds two reservations for, say, 8-9 September; the incoming version of the booking creates two reservations for 2-3 September in the same write. The first computes fine; the second inherits checkin = 8 September before its lines land, gets checkout = 3 September from those lines, and the whole import fails. The traceback is misleading, since the frame that raises belongs to the first (correct) reservation: reading its checkout triggers _compute_checkout for the whole pending batch.

Fix

  • Turn the check into @api.constrains("checkin", "checkout") so it runs at flush time, once every compute has been resolved, and drop the three calls made from inside the computes. The method keeps its name and its message, and it has no callers outside those computes.
  • The default branch of _compute_checkout was writing checkin instead of checkout, so a reservation added to a folio with neither dates nor lines never got its default checkout.
  • checkin_checkout_consecutive_dates raised ValueError: min() arg is an empty sequence on a reservation without lines, which is exactly the state an inconsistent checkin/checkout pair leaves behind. It now skips those and lets check_in_out_dates report them with a readable message.

Tests

Two tests are added:

  • test_reservation_default_dates_from_folio creates a reservation with neither dates nor lines on a folio that already holds one, and asserts it takes both dates from it. It fails on 16.0 (ValueError: min() arg is an empty sequence, the downstream symptom of the checkin/checkout mix-up) and passes with this change.
  • test_reservation_checkout_before_checkin asserts that a reservation ending before it starts is still rejected, now through the constraint.

The batch-create ordering described above is not covered by a test: reproducing it needs the extra create/write layers that sit on top of pms.reservation in a full deployment, and in a plain pms database the reservation lines are already in cache by the time _compute_checkin runs, so the default branch is never reached.

Full pms suite run before and after: same two pre-existing failures in both runs (test_pms_folio_priority_fiscal_position_property and test_do_payment_sets_payment_method_line), no new ones.

check_in_out_dates() was called from inside _compute_checkin,
_compute_checkout and _compute_reservation_line_ids, so it validated the
checkin/checkout pair while it was still being computed.

A reservation created without dates defaults its checkin to the one of the
first reservation of its folio. When the same write supplies the reservation
lines too, that default is only replaced once the lines are stored, so a
reservation of the batch can still be holding the inherited checkin while its
checkout has already been computed from its own lines. Adding to a folio
several reservations whose dates are earlier than the ones already in it -a
channel modification bringing a multi-room stay forward, for instance- then
failed with "Room line Check In Date Should be less than the Check Out Date!"
even though the values being stored were consistent.

Turn the check into a constraint on checkin and checkout so that it runs at
flush time, once every compute has been resolved, and drop the three calls
made from inside the computes.

Two defects in the same path are fixed as well:

* the default branch of _compute_checkout wrote checkin instead of checkout,
  so a reservation added to a folio with neither dates nor lines never got
  its default checkout;
* checkin_checkout_consecutive_dates raised "min() arg is an empty sequence"
  on a reservation without lines, which is the state an inconsistent
  checkin/checkout pair leaves behind. Those are now left to
  check_in_out_dates, which reports them with a readable message.
@DarioLodeiros

Copy link
Copy Markdown
Member Author

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 16.0-ocabot-merge-pr-445-by-DarioLodeiros-bump-minor, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 56c51b5 into OCA:16.0 Sep 7, 2026
5 of 7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at ac4fdbc. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants