From af14f257e928a5e6cd845b813d40321075c0395e Mon Sep 17 00:00:00 2001 From: Stefan Berndtsson Date: Thu, 27 Oct 2022 09:22:56 +0200 Subject: [PATCH] Bug 36303: Add after_circ_action hook action for checking in item that was not checked out To test: 1) Run tests in t/db_dependent/Koha/Plugins/Circulation_hooks.t Sponsored-by: Gothenburg University Library --- C4/Circulation.pm | 8 ++++++++ t/db_dependent/Koha/Plugins/Circulation_hooks.t | 11 +++++++---- t/lib/plugins/Koha/Plugin/Test.pm | 11 ++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 0a8df342638..f288923f533 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2767,6 +2767,14 @@ sub AddReturn { } + if ( !$issue ) { + Koha::Plugins->call( 'after_circ_action', { + action => 'checkin_no_issue', + payload => { + checkin => $item + } + }); + } return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ) ); } diff --git a/t/db_dependent/Koha/Plugins/Circulation_hooks.t b/t/db_dependent/Koha/Plugins/Circulation_hooks.t index 21880062993..e17d777bbcc 100755 --- a/t/db_dependent/Koha/Plugins/Circulation_hooks.t +++ b/t/db_dependent/Koha/Plugins/Circulation_hooks.t @@ -72,6 +72,7 @@ subtest 'after_circ_action() hook tests' => sub { my $biblio = $builder->build_sample_biblio(); my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); + my $item_no_issue = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); subtest 'AddIssue' => sub { plan tests => 2; @@ -102,7 +103,7 @@ subtest 'after_circ_action() hook tests' => sub { }; subtest 'AddReturn' => sub { - plan tests => 2; + plan tests => 3; t::lib::Mocks::mock_preference( 'BlockReturnOfWithdrawnItems', 1 ); $item_1->set( { withdrawn => 1 } )->store; @@ -115,11 +116,13 @@ subtest 'after_circ_action() hook tests' => sub { t::lib::Mocks::mock_preference( 'BlockReturnOfWithdrawnItems', 0 ); $item_1->set( { withdrawn => 0 } )->store; - warning_like { - AddReturn( $item_1->barcode, $patron->branchcode ); - } + warning_like { AddReturn( $item_1->barcode, $patron->branchcode ); } qr/after_circ_action called with action: checkin, ref: Koha::Old::Checkout/, 'AddReturn calls the after_circ_action hook'; + + warning_like { AddReturn( $item_no_issue->barcode, $patron->branchcode ); } + qr/after_circ_action called with action: checkin_no_issue, ref: Koha::Item/, + 'AddReturn calls the after_circ_action hook'; }; Koha::Plugins->RemovePlugins; diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm index 4d6bd517f69..88e091f4d6a 100644 --- a/t/lib/plugins/Koha/Plugin/Test.pm +++ b/t/lib/plugins/Koha/Plugin/Test.pm @@ -227,19 +227,24 @@ sub after_circ_action { my ( $self, $params ) = @_; my $action = $params->{action}; - my $checkout = $params->{payload}->{checkout}; my $payload = $params->{payload}; - my $type = $payload->{type}; - if ( $action eq 'renewal' ) { + my $checkout = $payload->{checkout}; Koha::Exception->throw( "after_circ_action called with action: $action, ref: " . ref($checkout) ); } elsif ( $action eq 'checkout' ) { + my $checkout = $payload->{checkout}; + my $type = $payload->{type}; Koha::Exception->throw( "after_circ_action called with action: $action, ref: " . ref($checkout) . " type: $type" ); } elsif ( $action eq 'checkin' ) { + my $checkout = $payload->{checkout}; Koha::Exception->throw( "after_circ_action called with action: $action, ref: " . ref($checkout) ); } + elsif ( $action eq 'checkin_no_issue' ) { + my $checkin = $payload->{checkin}; + Koha::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkin)); + } } sub after_hold_action { -- 2.51.2