[16.0][FIX] pms: validate reservation dates once both are computed - #445
Merged
OCA-git-bot merged 1 commit intoSep 7, 2026
Conversation
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.
Member
Author
|
/ocabot merge minor |
Contributor
|
On my way to merge this fine PR! |
Contributor
|
Congratulations, your PR was merged at ac4fdbc. Thanks a lot for contributing to OCA. ❤️ |
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.
Problem
check_in_out_dates()was called from inside_compute_checkin,_compute_checkoutand_compute_reservation_line_ids, so it validated thecheckin/checkoutpair while it was still being computed.A reservation created without dates defaults its
checkinto the one of the first reservation of its folio. When the same write also suppliesreservation_line_ids, that default is only replaced once the lines are stored, so a reservation of the batch can still be holding the inheritedcheckinwhile itscheckouthas 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: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 Septemberbefore its lines land, getscheckout = 3 Septemberfrom those lines, and the whole import fails. The traceback is misleading, since the frame that raises belongs to the first (correct) reservation: reading itscheckouttriggers_compute_checkoutfor the whole pending batch.Fix
@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._compute_checkoutwas writingcheckininstead ofcheckout, so a reservation added to a folio with neither dates nor lines never got its default checkout.checkin_checkout_consecutive_datesraisedValueError: min() arg is an empty sequenceon a reservation without lines, which is exactly the state an inconsistentcheckin/checkoutpair leaves behind. It now skips those and letscheck_in_out_datesreport them with a readable message.Tests
Two tests are added:
test_reservation_default_dates_from_foliocreates 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_checkinasserts 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/writelayers that sit on top ofpms.reservationin a full deployment, and in a plainpmsdatabase the reservation lines are already in cache by the time_compute_checkinruns, so the default branch is never reached.Full
pmssuite run before and after: same two pre-existing failures in both runs (test_pms_folio_priority_fiscal_position_propertyandtest_do_payment_sets_payment_method_line), no new ones.