[FIX] pms_sale: min_nights was never actually enforced - #444
Open
bretif wants to merge 1 commit into
Open
Conversation
_check_no_of_nights()'s condition (duration > min_nights and max_nights < duration) only rejects a reservation when its duration exceeds *both* bounds at once, so in practice only max_nights was ever checked: a property with min_nights=2 would happily accept a 1-night stay, and one with min_nights=max_nights=5 would accept a 3-night stay. Fix the condition to duration < min_nights or duration > max_nights, treating 0 as "no bound" on either side (matching the common Odoo convention for min/max quantity fields), rather than the previous behavior where min_nights=max_nights=0 rejected every reservation.
Contributor
|
Hi @max3903, |
bretif
marked this pull request as ready for review
August 30, 2026 16:13
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.
Bug
pms.reservation._check_no_of_nights()never actually enforcesmin_nights, regardless of its value. Its condition:only rejects a reservation when its duration exceeds both bounds at the same time — in practice this means only
max_nightsis ever checked,min_nightsis dead code. Verified directly against apms.property/pms.reservationpair:Fix
Corrected condition:
duration < min_nights or duration > max_nights, treating0on either bound as "no limit" (the common Odoo convention for min/max quantity fields).Behavior change to flag for review: previously, a property left at the default
min_nights=0/max_nights=0rejected every reservation (with the confusing message "must be between 0 and 0"). With this fix, an unconfigured property now has no stay-length restriction at all, rather than being implicitly unbookable. I don't see anything in the field definitions, views, demo data or existing tests suggesting the old all-rejecting behavior was intentional (nothing marks 0 as a "not for rent" flag), but flagging explicitly in case there's context I'm missing.Tests
Added 3 regression tests to
pms_sale/tests/test_pms_reservation.pycovering: a too-short stay against a realmin_nights, a fixed-length stay (min_nights == max_nights) below the required length, and an unconfigured (0/0) property. All go throughwrite()(real@api.constrainsdispatch), not a direct method call.Ran the full
pms_saletest suite locally (Odoo 19.0, PostgreSQL): 19/19 of the module's own tests pass with this change (one pre-existing, unrelated failure intest_onchange_property_id— a timezone-dependent assertion — is present identically on the unpatched19.0branch, confirmed by reverting and re-running).Found while validating this module for a downstream project's data model.