Koha-clms/svc
Martin Renvoize 2da3248b41
Bug 42997: Prevent renewals running into the next booking
CanBookBeRenewed checked bookings by asking Koha::Item->find_booking
for the first booking that clashes with the renewal period. When the
renewing patron's own booking satisfies this checkout, that booking is
returned first and renewal is allowed - subsequent bookings for the
item were never considered. A patron could therefore renew a booked
item straight through the start of the next patron's booking.

Additionally, when staff renew with an explicit due date (the renewal
due date input on the checkouts screen, or the hard due date on
circ/renew.pl), CanBookBeRenewed validated a *calculated* due date
whilst AddRenewal then applied the *requested* one, so the requested
date was never checked against bookings at all.

This patch:

* repeats the booking lookup with the patron's own booking excluded,
  refusing the renewal ('booked') when it would run into the next
  booking for the item
* adds an optional $date_due parameter to CanBookBeRenewed, used in
  place of the calculated due date for the bookings check, and threads
  the requested date through from svc/renew and circ/renew.pl

Test plan:
1) Run t/db_dependent/Circulation.t - the extended
   'CanBookBeRenewed | bookings' subtest covers both the calculated
   and requested due date cases
2) Check out a booked item to its patron, add a subsequent booking for
   another patron, and attempt to renew past the second booking's
   start date from the checkouts screen; confirm the renewal is
   refused as 'booked'

Sponsored-by: OpenFifth <https://openfifth.co.uk/\>
Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/\>
Signed-off-by: Hannah Dunne-Howrie <hdunne-howrie@westminster.gov.uk>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-03 15:53:53 +00:00
..
cataloguing
…
club
…
config Bug 42084: (QA follow-up) Simplify 2026-06-03 12:08:17 +00:00
letters
…
mana
…
members
…
records
…
virtualshelves Bug 40680: Fix svc/virtualshelves/search 2025-12-01 08:33:59 -07:00
article_request
…
authentication
…
authorised_values
…
barcode
…
bib
…
bib_framework
…
bib_profile
…
checkin
…
checkout_notes
…
checkouts Bug 37762: Circulation: Hook to checkouts/checkins 2026-05-08 12:25:43 -06:00
convert_report
…
cover_images
…
creator_batches
…
holds Bug 37762: (QA follow-up) remove reintroduced visual_hold_group_id 2026-05-15 08:11:01 -06:00
import_bib
…
localization Bug 38136: Refactor database translations (alternative) 2026-04-15 11:37:14 -06:00
new_bib
…
problem_reports
…
recall
…
renew Bug 42997: Prevent renewals running into the next booking 2026-09-03 15:53:53 +00:00
report Bug 41919: Limit number of current reports a single user can run simultaneously 2026-05-07 07:56:21 -06:00
return_claims
…
split_callnumbers
…