diff --git a/C4/Circulation.pm b/C4/Circulation.pm index abea785d9a..a3b77985cf 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1066,8 +1066,13 @@ sub CanBookBeIssued { # $patron = Koha::Patrons->find( $patron->borrowernumber ) ; # FIXME Refetch just in case, to avoid regressions. But must not be needed - if ( $patron->wants_check_for_previous_checkout && $patron->do_check_for_previous_checkout($item_unblessed) ) { - $needsconfirmation{PREVISSUE} = 1; + my $check_previous_checkout = $patron->do_check_for_previous_checkout($item_unblessed); + if ( $patron->wants_check_for_previous_checkout && $check_previous_checkout ) { + if ( $check_previous_checkout eq "currentlycheckedout" ) { + $needsconfirmation{CURRENTISSUE} = 1; + } else { + $needsconfirmation{PREVISSUE} = 1; + } } # diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 56df7f9b8d..55e0659957 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -865,6 +865,10 @@ sub do_check_for_previous_checkout { itemnumber => \@item_nos, }; + # Check current issues table + my $issues = Koha::Checkouts->search($criteria); + return "currentlycheckedout" if $issues->count; # 0 || N + my $delay = C4::Context->preference('CheckPrevCheckoutDelay') || 0; if ($delay) { my $dtf = Koha::Database->new->schema->storage->datetime_parser; @@ -872,13 +876,9 @@ sub do_check_for_previous_checkout { $criteria->{'returndate'} = { '>' => $dtf->format_datetime($newer_than), }; } - # Check current issues table - my $issues = Koha::Checkouts->search($criteria); - return 1 if $issues->count; # 0 || N - # Check old issues table my $old_issues = Koha::Old::Checkouts->search($criteria); - return $old_issues->count; # 0 || N + return $old_issues->count; # 0 || N } =head3 is_debarred diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index dd058abc9f..3514a4284e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -272,6 +272,10 @@
  • High demand item. Loan period shortened to [% HIGHHOLDS.duration | html %] days (due [% HIGHHOLDS.returndate | $KohaDates %]). Check out anyway?
  • [% END %] + [% IF CURRENTISSUE %] +
  • Patron has this title currently checked out: [% biblio.title | html %] [% IF biblio.author %]by [% biblio.author | html %][% END %]. Check out anyway?
  • + [% END %] + [% IF PREVISSUE %]
  • Patron has previously checked out this title: [% biblio.title | html %] [% IF biblio.author %]by [% biblio.author | html %][% END %]. Check out anyway?
  • [% END %] diff --git a/t/db_dependent/Patron/Borrower_PrevCheckout.t b/t/db_dependent/Patron/Borrower_PrevCheckout.t index ec3523d38e..9abd901448 100755 --- a/t/db_dependent/Patron/Borrower_PrevCheckout.t +++ b/t/db_dependent/Patron/Borrower_PrevCheckout.t @@ -8,7 +8,7 @@ use Koha::DateUtils qw( dt_from_string ); use Koha::Patrons; use Test::NoWarnings; -use Test::More tests => 62; +use Test::More tests => 64; use_ok('Koha::Patron'); @@ -311,6 +311,52 @@ BAIL_OUT("Issue failed") # Then test: my $cpvPmappings = [ + { + msg => "Same item, same patron [1]", + item => $item_1, + patron => $patron, + result => "currentlycheckedout", + }, + { + msg => "Diff item, same bib, same patron [1]", + item => $item_2, + patron => $patron, + result => "currentlycheckedout", + }, + { + msg => "Diff item, diff bib, same patron [0]", + item => $item_d, + patron => $patron, + result => 0, + }, + { + msg => "Same item, diff patron [0]", + item => $item_1, + patron => $patron_d, + result => 0, + }, + { + msg => "Diff item, same bib, diff patron [0]", + item => $item_2, + patron => $patron_d, + result => 0, + }, + { + msg => "Diff item, diff bib, diff patron [0]", + item => $item_d, + patron => $patron_d, + result => 0, + }, +]; + +test_it( $cpvPmappings, "PostIssue" ); + +# Return item_1 from patron: +BAIL_OUT("Return Failed") unless AddReturn( $item_1->{barcode}, $patron->{branchcode} ); + +#Since currently checked in item now return status "currentlycheckedout" we need use +#same test scenarions for returned item as above but without "currentlycheckedout" +$cpvPmappings = [ { msg => "Same item, same patron [1]", item => $item_1, @@ -349,11 +395,6 @@ my $cpvPmappings = [ }, ]; -test_it( $cpvPmappings, "PostIssue" ); - -# Return item_1 from patron: -BAIL_OUT("Return Failed") unless AddReturn( $item_1->{barcode}, $patron->{branchcode} ); - # Then: test_it( $cpvPmappings, "PostReturn" ); @@ -364,7 +405,18 @@ test_it( $cpvPmappings, "PostReturn" ); # whetherthe different combinational outcomes of the above return values in # CanBookBeIssued result in the appropriate $needsconfirmation. -# We want to test: +# We want to test when item is currently issued to the patron: +# - DESCRIPTION [RETURNVALUE (0/1)] +# - patron, !wants_check_for_previous_checkout, !do_check_for_previous_checkout +# [!$issuingimpossible,!$needsconfirmation->{CURRENTISSUE}] +# - patron, wants_check_for_previous_checkout, !do_check_for_previous_checkout +# [!$issuingimpossible,!$needsconfirmation->{CURRENTISSUE}] +# - patron, !wants_check_for_previous_checkout, do_check_for_previous_checkout +# [!$issuingimpossible,!$needsconfirmation->{CURRENTISSUE}] +# - patron, wants_check_for_previous_checkout, do_check_for_previous_checkout +# [!$issuingimpossible,$needsconfirmation->{CURRENTISSUE}] + +# And we also need to test when item has been previously issued to the patron: # - DESCRIPTION [RETURNVALUE (0/1)] # - patron, !wants_check_for_previous_checkout, !do_check_for_previous_checkout # [!$issuingimpossible,!$needsconfirmation->{PREVISSUE}] @@ -424,6 +476,32 @@ my $CBBI_mappings = [ }, ]; +# Tests +map { + t::lib::Mocks::mock_preference( 'checkprevcheckout', $_->{syspref} ); + my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $_->{item}->{barcode} ); + is( $needsconfirmation->{CURRENTISSUE}, $_->{result}, $_->{msg} ); +} @{$CBBI_mappings}; + +# Return $prev_item from patron: +BAIL_OUT("Return Failed") unless AddReturn( $prev_item->{barcode}, $patron->{branchcode} ); + +# Mappings +$CBBI_mappings = [ + { + syspref => 'hardno', + item => $prev_item, + result => undef, + msg => "patron, !wants_check_for_previous_checkout, do_check_for_previous_checkout" + }, + { + syspref => 'hardyes', + item => $prev_item, + result => 1, + msg => "patron, wants_check_for_previous_checkout, do_check_for_previous_checkout" + }, +]; + # Tests map { t::lib::Mocks::mock_preference( 'checkprevcheckout', $_->{syspref} ); @@ -456,7 +534,7 @@ subtest 'Check previous checkouts for serial' => sub { AddIssue( $patron, $item1->barcode ); is( - $patron->do_check_for_previous_checkout( $item1->unblessed ), 1, + $patron->do_check_for_previous_checkout( $item1->unblessed ), "currentlycheckedout", 'Check only one item if bibliographic record is serial' ); is(