From de25586ba0c89ac2f843f772114b8297066e2d88 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 28 Apr 2021 14:37:12 -0300 Subject: [PATCH] Bug 28254: Add 'override' parameter to Koha::Hold->set_pickup_location This patch adds a new parameter to the method. If passed+true it makes the method skip the pickup validation test. Tests and POD added for this change. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Hold.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Hold.pm | 20 +++++++++++++++++--- t/db_dependent/Koha/Hold.t | 6 +++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 56671f19a8..793b4983bc 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -47,7 +47,7 @@ Koha::Hold - Koha Hold object class =head1 API -=head2 Class Methods +=head2 Class methods =cut @@ -254,11 +254,19 @@ sub is_pickup_location_valid { =head3 set_pickup_location - $hold->set_pickup_location({ library_id => $library->id }); + $hold->set_pickup_location( + { + library_id => $library->id, + [ override => 0|1 ] + } + ); Updates the hold pickup location. It throws a I if the passed pickup location is not valid. +Note: It is up to the caller to verify if I is set when setting the +B parameter. + =cut sub set_pickup_location { @@ -267,7 +275,13 @@ sub set_pickup_location { Koha::Exceptions::MissingParameter->throw('The library_id parameter is mandatory') unless $params->{library_id}; - if ( $self->is_pickup_location_valid({ library_id => $params->{library_id} }) ) { + if ( + $params->{override} + || $self->is_pickup_location_valid( + { library_id => $params->{library_id} } + ) + ) + { # all good, set the new pickup location $self->branchcode( $params->{library_id} )->store; } diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index a6a5c4a7d6..736b32b305 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -56,7 +56,7 @@ subtest 'patron() tests' => sub { subtest 'set_pickup_location() tests' => sub { - plan tests => 10; + plan tests => 11; $schema->storage->txn_begin; @@ -125,6 +125,10 @@ subtest 'set_pickup_location() tests' => sub { $item_hold->discard_changes; is( $item_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); + $item_hold->set_pickup_location({ library_id => $library_1->branchcode, override => 1 }); + $item_hold->discard_changes; + is( $item_hold->branchcode, $library_1->branchcode, 'branchcode changed because of \'override\'' ); + $ret = $item_hold->set_pickup_location({ library_id => $library_2->id }); is( ref($ret), 'Koha::Hold', 'self is returned' ); -- 2.39.5