Bug 39912: Update RealTimeHoldsQueue when hold pickup location is updated

When a hold's pickup location is changed we should rebuild the holds queue.

To test:
1 - Enable RealTimeHoldsQueue
2 - Enable LocalHoldsPriority where pickup library matches home library
3 - Place two biblio level holds on a bib with one item for two different patrons for delivery to a different library then the home library
4 - Check the queue - firstpatron should have priority
5 - Change the pickup location for the second hold to be picked up at the home library
6 - Check the queue, unchanged
7 - Change the pickup location back
8 - Apply patch, restart all
9 - Change the pickup location to the items home library again
10 - Check the queue
11 - Second patron has now been given priority

Signed-off-by: Michelle Spinney <mspinney@clamsnet.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 3664281d37)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Nick Clemens 2025-05-15 18:27:07 +00:00 committed by Paul Derscheid
parent 816b4537e9
commit 87043c9f53
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 46 additions and 5 deletions

View File

@ -972,6 +972,9 @@ sub store {
}
}
}
if ( exists $updated_columns{branchcode} ) {
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $self->biblionumber ] } );
}
}
$self = $self->SUPER::store;

View File

@ -346,25 +346,28 @@ subtest 'fill() tests' => sub {
subtest 'holds_queue update tests' => sub {
plan tests => 1;
plan tests => 2;
my $biblio = $builder->build_sample_biblio;
my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
# The check of the pref is in the Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue
# so we mock the base enqueue method here to see if it is called
my $mock = Test::MockModule->new('Koha::BackgroundJob');
$mock->mock(
'enqueue',
sub {
my ( $self, $args ) = @_;
is_deeply(
$args->{biblio_ids},
$args->{job_args}->{biblio_ids},
[ $biblio->id ],
'->fill triggers a holds queue update for the related biblio'
'when pref enabled the previous action triggers a holds queue update for the related biblio'
);
}
);
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
diag("Filling a hold when pref enabled should trigger a test");
$builder->build_object(
{
class => 'Koha::Holds',
@ -376,7 +379,7 @@ subtest 'fill() tests' => sub {
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
# this call shouldn't add a new test
diag("Filling a hold when pref disabled should not trigger a test");
$builder->build_object(
{
class => 'Koha::Holds',
@ -385,6 +388,41 @@ subtest 'fill() tests' => sub {
}
}
)->fill;
my $library_1 = $builder->build_object(
{
class => 'Koha::Libraries',
}
)->store;
my $library_2 = $builder->build_object(
{
class => 'Koha::Libraries',
}
)->store;
my $hold = $builder->build_object(
{
class => 'Koha::Holds',
value => {
biblionumber => $biblio->id,
branchcode => $library_1->branchcode,
}
}
)->store;
# Pref is off, no test triggered
diag("Updating a hold location when pref disabled should not trigger a test");
$hold->branchcode( $library_2->branchcode )->store;
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
diag("Updating a hold location when pref enabled should trigger a test");
# Pref is on, test triggered
$hold->branchcode( $library_1->branchcode )->store;
diag("Update with no change to pickup location should not trigger a test");
$hold->branchcode( $library_1->branchcode )->store;
};
$schema->storage->txn_rollback;