From 620527f97140370eedc6c2fb35930f770b97ffb3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 27 Mar 2024 17:29:00 +0000 Subject: [PATCH] Bug 34440: Take preparation period into account at checkout This patch ensures we catch checkouts that would interfer with the preparation period set for an existing booking by adding said period to the bookings search. We also reduce the proposed due date for the checkout to be confirmed by the preparation period for the item. Test plan 1) Set a booking preparation period for an itemtype 2) Add a booking for an item with that itemtype to fall beyond the due date that the item would be assigned if you were to check it out now to your test user, but within the number of days you've set for your preparation period. 3) Attempt to check the item out to your test user. 4) Note that we catch the booking and warn and that the latest return date suggested take the preparation period into account. Sponsored-by: Cuyahoga County Public Library Signed-off-by: Kristi Krueger Signed-off-by: Paul Derscheid Signed-off-by: Katrin Fischer --- Koha/Item.pm | 10 ++++++++++ circ/circulation.pl | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index b9e35ae352..d2e475df02 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -602,6 +602,16 @@ sub find_booking { my $due_date = $params->{due_date}; my $biblio = $self->biblio; + my $rule = Koha::CirculationRules->get_effective_rule( + { + rule_name => 'bookings_lead_period', + itemtype => $self->effective_itemtype, + branchcode => "*" + } + ); + my $preparation_period = $rule ? $rule->rule_value : 0; + $due_date = $due_date->clone->add( days => $preparation_period ); + my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $bookings = $biblio->bookings( [ diff --git a/circ/circulation.pl b/circ/circulation.pl index acabfa4d1d..9230347ce0 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -52,6 +52,7 @@ use Koha::Plugins; use Koha::Database; use Koha::BiblioFrameworks; use Koha::Items; +use Koha::CirculationRules; use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::Patron::Modifications; @@ -482,8 +483,17 @@ if (@$barcodes && $op eq 'cud-checkout') { $template_params->{NEEDSCONFIRMATION} = 1; $confirm_required = 1; if ( $needsconfirmation_key eq 'BOOKED_TO_ANOTHER' ) { + my $rule = Koha::CirculationRules->get_effective_rule( + { + rule_name => 'bookings_lead_period', + itemtype => $item->effective_itemtype, + branchcode => "*" + } + ); + my $preparation_period = $rule ? $rule->rule_value : 1; my $reduceddue = - dt_from_string( $$needsconfirmation{$needsconfirmation_key}->start_date )->subtract( days => 1 ); + dt_from_string( $$needsconfirmation{$needsconfirmation_key}->start_date ) + ->subtract( days => $preparation_period ); $template_params->{reduceddue} = $reduceddue; } } -- 2.39.5