[Bug 43108] New: Add a REST API endpoint for a biblio's booking availability over a date range
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 Bug ID: 43108 Summary: Add a REST API endpoint for a biblio's booking availability over a date range Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Circulation Assignee: koha-bugs@lists.koha-community.org Reporter: paul.derscheid@lmscloud.de QA Contact: testopia@bugs.koha-community.org CC: gmcharlt@gmail.com, kyle@bywatersolutions.com Target Milestone: --- Booking availability (which of a record's bookable items can be booked on which dates, given the lead/trail circulation rules, existing bookings, current checkouts, and the pickup library's closed days) is computed server-side as the single source of truth and exposed over REST. One implementation backs both display and enforcement so they cannot drift; the server returns a compact per-date map rather than making each consumer fetch and process all of a record's bookings and checkouts; and any consumer, whether the Vue booking modal (Bug 41129), another UI, or a third-party integration building its own booking flow, can query it without re-implementing the rules. GET /biblios/{biblio_id}/booking_availability ?from_date=YYYY-MM-DD&to_date=YYYY-MM-DD (required, inclusive, <= 366 days) [&pickup_library_id=...] [&patron_id=...] [&item_type_id=...] [&item_id=...] [&excluded_booking_id=...] (rule/context + edit-exclude) It returns the bookable item ids and a sparse per-(date, item) map. Each cell is an availability result: { "item_ids": [101, 102], "availability": { "2026-08-10": { "101": { "blockers": { "booking": 1 }, "confirms": {}, "warnings": {} }, "102": { "blockers": { "lead": 1 }, "confirms": {}, "warnings": { "holiday": 1 } } } } } - blockers prevent a new booking (booking, checkout, lead, trail); an item with no blockers on a date is bookable, so its available dates are the complement. - warnings are advisory display context only (holiday, lead_floor, lead_theoretical). - confirms is always empty for bookings but present so each cell is a complete availability result. The response shape follows the availability-class pattern currently being established: Bug 41728 (Koha::Result::Availability, to_hashref, where each cell is that shape); Bug 42386 (Koha::{Patron,Item,Biblio}::Availability::Hold, which sets the namespace and snake_case reasons; the class here is Koha::Biblio::Availability::Booking); Bug 42385 and Bug 42387. To stay more or less independent of that series, the class returns a plain hashref rather than subclassing the not-yet-merged Koha::Result::Availability; the shape is compatible, so switching to the real object later is a drop-in change. Booking and checkout day boundaries are attributed to the library timezone (consistent with Bug 42868), matching how bookings are stored and enforced. When item_id names a single item, its own effective item type governs the lead/trail rules (the type enforcement will use), overriding any item_type_id passed alongside it. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@gmail.com, | |martin.renvoize@openfifth.c | |o.uk, tomascohen@gmail.com Blocks| |41129 See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=41728, | |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42385, | |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42386, | |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42387, | |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42868 Circulation| |Bookings function| | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41129 [Bug 41129] Migrate place_booking.js to a Vue island. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited| |Büchereizentrale list of Sponsors| |Schleswig-Holstein | |<https://www.bz-sh.de/> Sponsorship status|--- |Sponsored Assignee|koha-bugs@lists.koha-commun |paul.derscheid@lmscloud.de |ity.org | Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #1 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 202171 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202171&action=edit Bug 43108: Add tests Unit tests for Koha::Biblio::Availability::Booking and API tests for GET /biblios/{biblio_id}/booking_availability. They fail without the following patch. Test plan: prove t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> Assisted-by: Fable 5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #2 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 202172 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202172&action=edit Bug 43108: Add booking availability endpoint GET /api/v1/biblios/{biblio_id}/booking_availability returns, for each calendar date in the requested range, the booking availability of a record's bookable items: per (date, item), the blockers that prevent a new booking and the warnings that are advisory context only. It is the server-side source of truth for the booking calendar, so display and enforcement share one implementation. - Koha::Biblio::Availability::Booking computes each per-(date, item) cell as an availability result (blockers: booking, checkout, lead, trail; warnings: holiday, lead_floor, lead_theoretical), shaped like Koha::Result::Availability->to_hashref; namespace and vocabulary follow bug 41728 / bug 42386. Koha::Biblio->booking_availability is a thin wrapper around it - lead/trail windows derive from the effective bookings_lead_period and bookings_trail_period rules for the passed pickup library, patron and item type context; one rule set applies to every existing booking, matching the booking calendar - closed days of the pickup library are marked via Koha::Calendar - booking dates and checkout due dates are attributed to their library timezone calendar day (consistent with bug 42868) - excluded_booking_id leaves out the booking being edited; item_id restricts the calculation to a single item - the route requires the circulate/manage_bookings permission, same as GET /biblios/{biblio_id}/bookings Test plan: 1. Run the tests from the previous patch: prove t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t 2. Regenerate the spec bundle (yarn api:bundle) or remove api/v1/swagger/swagger_bundle.json, restart plack, then with a record that has bookable items: curl -u koha:koha "<staff>/api/v1/biblios/<biblio_id>/booking_availability?from_date=2026-07-01&to_date=2026-07-31&pickup_library_id=<branch>" 3. Confirm booked/lead/trail/holiday dates match the booking modal's calendar for the same record and context Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> Assisted-by: Fable 5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |42207 Comma delimited|Büchereizentrale |Büchereizentrale list of Sponsors|Schleswig-Holstein |Schleswig-Holstein |<https://www.bz-sh.de/> |<https://www.bz-sh.de/> Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42207 [Bug 42207] Allow library embed on GET /patrons/{patron_id} -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |david@davidnind.com --- Comment #3 from David Nind <david@davidnind.com> --- I can't reproduce the test failures with only the first patch applied: - Fails as it doesn't exist yet: prove t/db_dependent/Koha/Biblio/Availability/Booking.t - Pass: prove t/db_dependent/Koha/Biblio.t and prove t/db_dependent/api/v1/biblios.t Testing notes (using KTD): 1. I added a holiday using Tools > Calendar for 2026-07-30 2. I enabled bookings and placed a booking on Programming Perl (262) from 2026-07-29 to 2026-07-31 for Mary Burton, with the pickup at Centerville. 3. curl -u koha:koha "[staff-interface-url]:8081/api/v1/biblios/262/booking_availability?from_date=2026-07-01&to_date=2026-07-31&pickup_library_id=CPL" or via URL request: { "availability": { "2026-07-29": { "578": { "blockers": { "booking": 1 }, "confirms": { }, "warnings": { } } }, "2026-07-30": { "578": { "blockers": { "booking": 1 }, "confirms": { }, "warnings": { "holiday": 1 } } }, "2026-07-31": { "578": { "blockers": { "booking": 1 }, "confirms": { }, "warnings": { } } } }, "item_ids": [578] } -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |release-notes-needed -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #4 from David Nind <david@davidnind.com> --- (In reply to David Nind from comment #3)
I can't reproduce the test failures with only the first patch applied: - Fails as it doesn't exist yet: prove t/db_dependent/Koha/Biblio/Availability/Booking.t - Pass: prove t/db_dependent/Koha/Biblio.t and prove t/db_dependent/api/v1/biblios.t
Ignore what I just said - not sure what I was thinking/doing. The new test does exist with the first patch! I do get test failures now (with and without doing a yarn build and restart_all). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited|Büchereizentrale |Büchereizentrale list of Sponsors|Schleswig-Holstein |Schleswig-Holstein |<https://www.bz-sh.de/> |<https://www.bz-sh.de/>, | |Büchereizentrale | |Schleswig-Holstein | |<https://www.bz-sh.de/> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited|Büchereizentrale |Büchereizentrale list of Sponsors|Schleswig-Holstein |Schleswig-Holstein |<https://www.bz-sh.de/>, |<https://www.bz-sh.de/> |Büchereizentrale | |Schleswig-Holstein | |<https://www.bz-sh.de/> | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited|Büchereizentrale |Büchereizentrale list of Sponsors|Schleswig-Holstein |Schleswig-Holstein |<https://www.bz-sh.de/> |<https://www.bz-sh.de/>, | |Büchereizentrale | |Schleswig-Holstein | |<https://www.bz-sh.de/> Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #202171|0 |1 is obsolete| | Attachment #202172|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #5 from David Nind <david@davidnind.com> --- Created attachment 202190 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202190&action=edit Bug 43108: Add tests Unit tests for Koha::Biblio::Availability::Booking and API tests for GET /biblios/{biblio_id}/booking_availability. They fail without the following patch. Test plan: prove t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> Assisted-by: Fable 5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #6 from David Nind <david@davidnind.com> --- Created attachment 202191 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202191&action=edit Bug 43108: Add booking availability endpoint GET /api/v1/biblios/{biblio_id}/booking_availability returns, for each calendar date in the requested range, the booking availability of a record's bookable items: per (date, item), the blockers that prevent a new booking and the warnings that are advisory context only. It is the server-side source of truth for the booking calendar, so display and enforcement share one implementation. - Koha::Biblio::Availability::Booking computes each per-(date, item) cell as an availability result (blockers: booking, checkout, lead, trail; warnings: holiday, lead_floor, lead_theoretical), shaped like Koha::Result::Availability->to_hashref; namespace and vocabulary follow bug 41728 / bug 42386. Koha::Biblio->booking_availability is a thin wrapper around it - lead/trail windows derive from the effective bookings_lead_period and bookings_trail_period rules for the passed pickup library, patron and item type context; one rule set applies to every existing booking, matching the booking calendar - closed days of the pickup library are marked via Koha::Calendar - booking dates and checkout due dates are attributed to their library timezone calendar day (consistent with bug 42868) - excluded_booking_id leaves out the booking being edited; item_id restricts the calculation to a single item - the route requires the circulate/manage_bookings permission, same as GET /biblios/{biblio_id}/bookings Test plan: 1. Run the tests from the previous patch: prove t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t 2. Regenerate the spec bundle (yarn api:bundle) or remove api/v1/swagger/swagger_bundle.json, restart plack, then with a record that has bookable items: curl -u koha:koha "<staff>/api/v1/biblios/<biblio_id>/booking_availability?from_date=2026-07-01&to_date=2026-07-31&pickup_library_id=<branch>" 3. Confirm booked/lead/trail/holiday dates match the booking modal's calendar for the same record and context Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> Assisted-by: Fable 5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited|Büchereizentrale |Büchereizentrale list of Sponsors|Schleswig-Holstein |Schleswig-Holstein |<https://www.bz-sh.de/>, |<https://www.bz-sh.de/> |Büchereizentrale | |Schleswig-Holstein | |<https://www.bz-sh.de/> | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #7 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Hi David, thanks so much for testing this! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited|Büchereizentrale |Büchereizentrale list of Sponsors|Schleswig-Holstein |Schleswig-Holstein |<https://www.bz-sh.de/> |<https://www.bz-sh.de/>, | |Büchereizentrale | |Schleswig-Holstein | |<https://www.bz-sh.de/> Depends on| |41728 QA Contact|testopia@bugs.koha-communit |martin.renvoize@openfifth.c |y.org |o.uk Status|Signed Off |Passed QA Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41728 [Bug 41728] Add `Koha::Item::Availability::Checkin` to centralize logic -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #202190|0 |1 is obsolete| | Attachment #202191|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #8 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202381 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202381&action=edit Bug 43108: Add tests Unit tests for Koha::Biblio::Availability::Booking and API tests for GET /biblios/{biblio_id}/booking_availability. They fail without the following patch. Test plan: prove t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> Assisted-by: Fable 5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #9 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202382 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202382&action=edit Bug 43108: Add booking availability endpoint GET /api/v1/biblios/{biblio_id}/booking_availability returns, for each calendar date in the requested range, the booking availability of a record's bookable items: per (date, item), the blockers that prevent a new booking and the warnings that are advisory context only. It is the server-side source of truth for the booking calendar, so display and enforcement share one implementation. - Koha::Biblio::Availability::Booking computes each per-(date, item) cell as an availability result (blockers: booking, checkout, lead, trail; warnings: holiday, lead_floor, lead_theoretical), shaped like Koha::Result::Availability->to_hashref; namespace and vocabulary follow bug 41728 / bug 42386. Koha::Biblio->booking_availability is a thin wrapper around it - lead/trail windows derive from the effective bookings_lead_period and bookings_trail_period rules for the passed pickup library, patron and item type context; one rule set applies to every existing booking, matching the booking calendar - closed days of the pickup library are marked via Koha::Calendar - booking dates and checkout due dates are attributed to their library timezone calendar day (consistent with bug 42868) - excluded_booking_id leaves out the booking being edited; item_id restricts the calculation to a single item - the route requires the circulate/manage_bookings permission, same as GET /biblios/{biblio_id}/bookings Test plan: 1. Run the tests from the previous patch: prove t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t 2. Regenerate the spec bundle (yarn api:bundle) or remove api/v1/swagger/swagger_bundle.json, restart plack, then with a record that has bookable items: curl -u koha:koha "<staff>/api/v1/biblios/<biblio_id>/booking_availability?from_date=2026-07-01&to_date=2026-07-31&pickup_library_id=<branch>" 3. Confirm booked/lead/trail/holiday dates match the booking modal's calendar for the same record and context Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> Assisted-by: Fable 5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #10 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202383 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202383&action=edit Bug 43108: (QA follow-up) Use Koha::Result::Availability for per-cell results Build each per-(date, item) cell as a Koha::Result::Availability object (add_blocker/add_warning) instead of a hand-rolled hashref, converting to the wire shape via ->to_hashref only at the end of check(). This aligns booking availability with the result-object pattern introduced by bug 41728 and used by bug 42386's checkout/hold availability, instead of merely mimicking its hashref shape. Depends on Bug 41728 (Koha::Result::Availability), brought onto this branch in the preceding commit. No change to the returned JSON/hashref shape or to any public API. Test plan: prove t/Koha/Result/Availability.t \ t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #11 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202384 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202384&action=edit Bug 43108: (QA follow-up) Add tests for booking window edge cases Cover three scenarios raised in QA review that weren't previously exercised: - Two bookings on the same item close enough that one's trail window collides with the other's lead window, and that a hard lead blocker and a soft lead_theoretical warning can legitimately coexist on the same day. - A booking whose span starts before and ends after the requested from/to range, verifying _mark's day-range clamping and that the lead/trail windows around the booking's true start/end (which fall outside the requested range) don't leak into it. - Circulation rules with bookings_lead_period/bookings_trail_period explicitly set to 0, as opposed to no rule at all, to confirm both resolve identically to "no lead/trail window" via the `|| 0` fallback. Test plan: prove t/db_dependent/Koha/Biblio/Availability/Booking.t Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #12 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205300 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205300&action=edit Bug 43108: (QA follow-up) Cover the 366-day availability window boundary The existing "range too long" test only checked a range well past the limit (400 days); add the exact 366-day boundary (accepted) alongside it to catch an off-by-one in the <= comparison. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |26.11 Initiative type|--- |Feature -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #202381|0 |1 is obsolete| | Attachment #202382|0 |1 is obsolete| | Attachment #202383|0 |1 is obsolete| | Attachment #202384|0 |1 is obsolete| | Attachment #205300|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #13 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205492 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205492&action=edit Bug 43108: Add tests Unit tests for Koha::Biblio::Availability::Booking and API tests for GET /biblios/{biblio_id}/booking_availability. They fail without the following patch. Test plan: prove t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> Assisted-by: Fable 5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #14 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205493 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205493&action=edit Bug 43108: Add booking availability endpoint GET /api/v1/biblios/{biblio_id}/booking_availability returns, for each calendar date in the requested range, the booking availability of a record's bookable items: per (date, item), the blockers that prevent a new booking and the warnings that are advisory context only. It is the server-side source of truth for the booking calendar, so display and enforcement share one implementation. - Koha::Biblio::Availability::Booking computes each per-(date, item) cell as an availability result (blockers: booking, checkout, lead, trail; warnings: holiday, lead_floor, lead_theoretical), shaped like Koha::Result::Availability->to_hashref; namespace and vocabulary follow bug 41728 / bug 42386. Koha::Biblio->booking_availability is a thin wrapper around it - lead/trail windows derive from the effective bookings_lead_period and bookings_trail_period rules for the passed pickup library, patron and item type context; one rule set applies to every existing booking, matching the booking calendar - closed days of the pickup library are marked via Koha::Calendar - booking dates and checkout due dates are attributed to their library timezone calendar day (consistent with bug 42868) - excluded_booking_id leaves out the booking being edited; item_id restricts the calculation to a single item - the route requires the circulate/manage_bookings permission, same as GET /biblios/{biblio_id}/bookings Test plan: 1. Run the tests from the previous patch: prove t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t 2. Regenerate the spec bundle (yarn api:bundle) or remove api/v1/swagger/swagger_bundle.json, restart plack, then with a record that has bookable items: curl -u koha:koha "<staff>/api/v1/biblios/<biblio_id>/booking_availability?from_date=2026-07-01&to_date=2026-07-31&pickup_library_id=<branch>" 3. Confirm booked/lead/trail/holiday dates match the booking modal's calendar for the same record and context Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> Assisted-by: Fable 5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #15 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205494 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205494&action=edit Bug 43108: (QA follow-up) Use Koha::Result::Availability for per-cell results Build each per-(date, item) cell as a Koha::Result::Availability object (add_blocker/add_warning) instead of a hand-rolled hashref, converting to the wire shape via ->to_hashref only at the end of check(). This aligns booking availability with the result-object pattern introduced by bug 41728 and used by bug 42386's checkout/hold availability, instead of merely mimicking its hashref shape. Depends on Bug 41728 (Koha::Result::Availability), brought onto this branch in the preceding commit. No change to the returned JSON/hashref shape or to any public API. Test plan: prove t/Koha/Result/Availability.t \ t/db_dependent/Koha/Biblio/Availability/Booking.t \ t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #16 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205495 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205495&action=edit Bug 43108: (QA follow-up) Add tests for booking window edge cases Cover three scenarios raised in QA review that weren't previously exercised: - Two bookings on the same item close enough that one's trail window collides with the other's lead window, and that a hard lead blocker and a soft lead_theoretical warning can legitimately coexist on the same day. - A booking whose span starts before and ends after the requested from/to range, verifying _mark's day-range clamping and that the lead/trail windows around the booking's true start/end (which fall outside the requested range) don't leak into it. - Circulation rules with bookings_lead_period/bookings_trail_period explicitly set to 0, as opposed to no rule at all, to confirm both resolve identically to "no lead/trail window" via the `|| 0` fallback. Test plan: prove t/db_dependent/Koha/Biblio/Availability/Booking.t Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #17 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205496 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205496&action=edit Bug 43108: (QA follow-up) Cover the 366-day availability window boundary The existing "range too long" test only checked a range well past the limit (400 days); add the exact 366-day boundary (accepted) alongside it to catch an off-by-one in the <= comparison. Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43108 --- Comment #18 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205497 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205497&action=edit Bug 43108: (QA follow-up) Test that cancelled/completed bookings don't block availability _mark_bookings excludes cancelled and completed bookings from the conflict/blocker calculation (status => { -not_in => [...] }), but no existing fixture ever created a booking in either of those statuses, so the exclusion itself was unverified. Flipping -not_in to -in would currently pass every test in this file. Add a case with one active, one cancelled and one completed booking on otherwise-identical items, asserting the active booking still blocks while the other two don't. Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org