Bug 41886 - Biblio::check_booking counts checkouts on non-bookable items causing false clashes
Summary: Biblio::check_booking counts checkouts on non-bookable items causing false cl...
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Paul Derscheid
QA Contact: Testopia
URL:
Keywords:
Depends on: 29002
Blocks:
  Show dependency treegraph
 
Reported: 2026-02-19 10:39 UTC by Paul Derscheid
Modified: 2026-02-20 12:23 UTC (History)
3 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function: Bookings


Attachments
Bug 41886: Filter checkouts to bookable items in check_booking (4.55 KB, patch)
2026-02-19 10:43 UTC, Paul Derscheid
Details | Diff | Splinter Review
Bug 41886: Filter checkouts to bookable items in check_booking (4.60 KB, patch)
2026-02-20 12:22 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Derscheid 2026-02-19 10:39:35 UTC
- Biblio::check_booking uses $self->current_checkouts to count checked-out items overlapping with a booking period
- This counts checkouts on ALL items for the biblio, including non-bookable ones (e.g. items with an excluded item type)
- When only a subset of items are bookable, checkouts on non-bookable siblings incorrectly reduce the available pool, producing false clashes
- The integer-based counting ($booked_count) can also double-count an item that has both an active booking and an active checkout, further inflating the unavailable count

Steps to reproduce:
- Have a biblio with multiple items where only some are bookable
- Check out one or more of the non-bookable items
- Create a booking on one of the bookable items
- Clash is incorrectly detected even though all bookable items are available
Comment 1 Paul Derscheid 2026-02-19 10:43:55 UTC
Created attachment 193375 [details] [review]
Bug 41886: Filter checkouts to bookable items in check_booking

- Biblio::check_booking counts current checkouts toward the
  unavailable pool to detect booking clashes
- It counts checkouts on ALL items for the biblio, including
  non-bookable ones (e.g. items with an excluded item type)
- When only a subset of items are bookable, checkouts on
  non-bookable siblings incorrectly reduce the available pool,
  producing false clashes
- Restrict the checkout query to only count items whose
  itemnumber is in the bookable items set

To test:
1. Have a biblio with at least two items, where one item is
   bookable and the other is not (bookable = 0).
2. Check out the non-bookable item to a patron.
3. Attempt to create a booking for the bookable item.
4. Without the patch: a clash is detected even though the
   bookable item is available.
5. Apply the patch.
6. Repeat steps 2-3.
7. Verify the booking succeeds without a false clash.
8. Run: prove t/db_dependent/Koha/Biblio.t
   and confirm the new subtest
   "checkouts on non-bookable items do not cause false clashes"
   passes.
Comment 2 David Nind 2026-02-20 12:22:44 UTC
Created attachment 193533 [details] [review]
Bug 41886: Filter checkouts to bookable items in check_booking

- Biblio::check_booking counts current checkouts toward the
  unavailable pool to detect booking clashes
- It counts checkouts on ALL items for the biblio, including
  non-bookable ones (e.g. items with an excluded item type)
- When only a subset of items are bookable, checkouts on
  non-bookable siblings incorrectly reduce the available pool,
  producing false clashes
- Restrict the checkout query to only count items whose
  itemnumber is in the bookable items set

To test:
1. Have a biblio with at least two items, where one item is
   bookable and the other is not (bookable = 0).
2. Check out the non-bookable item to a patron.
3. Attempt to create a booking for the bookable item.
4. Without the patch: a clash is detected even though the
   bookable item is available.
5. Apply the patch.
6. Repeat steps 2-3.
7. Verify the booking succeeds without a false clash.
8. Run: prove t/db_dependent/Koha/Biblio.t
   and confirm the new subtest
   "checkouts on non-bookable items do not cause false clashes"
   passes.

Signed-off-by: David Nind <david@davidnind.com>