From 6ce96896f07f906fe0ed12430f3e81cac32b4957 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 2 May 2016 14:44:49 +0100 Subject: [PATCH] Bug 16413: Change prototype of GetSoonestRenewDate Same change as previous patch for the GetSoonestRenewDate subroutine. Test plan: Make sure this change does not introduce regressions on bug 7413. --- C4/Circulation.pm | 28 ++++++++++++---------------- circ/renew.pl | 7 +++++-- opac/opac-user.pl | 9 +++++++-- t/db_dependent/Circulation.t | 8 +++++--- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 7ac097d..f758978 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3169,14 +3169,15 @@ sub GetRenewCount { =head2 GetSoonestRenewDate - $NoRenewalBeforeThisDate = &GetSoonestRenewDate($borrowernumber, $itemnumber); + $NoRenewalBeforeThisDate = &GetSoonestRenewDate( { patron => $patron, item => $item } ); Find out the soonest possible renew date of a borrowed item. -C<$borrowernumber> is the borrower number of the patron who currently -has the item on loan. +C<$patron> is the patron who currently has the item on loan. -C<$itemnumber> is the number of the item to renew. +C<$item> is the item to renew. + +C<$issue> is the issue to renew. C<$GetSoonestRenewDate> returns the DateTime of the soonest possible renew date, based on the value "No renewal before" of the applicable @@ -3187,20 +3188,15 @@ cannot be found. =cut sub GetSoonestRenewDate { - my ( $borrowernumber, $itemnumber ) = @_; - - my $dbh = C4::Context->dbh; - - my $item = GetItem($itemnumber) or return; - my $itemissue = GetItemIssue($itemnumber) or return; + my ( $params ) = @_; - $borrowernumber ||= $itemissue->{borrowernumber}; - my $borrower = C4::Members::GetMemberDetails($borrowernumber) - or return; + my $patron = $params->{patron} or return; + my $item = $params->{item} or return; + my $issue = $params->{issue} or return; - my $branchcode = _GetCircControlBranch( $item, $borrower ); + my $branchcode = _GetCircControlBranch( $item, $patron ); my $issuingrule = - GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode ); + GetIssuingRule( $patron->{categorycode}, $item->{itype}, $branchcode ); my $now = dt_from_string; @@ -3208,7 +3204,7 @@ sub GetSoonestRenewDate { and $issuingrule->{norenewalbefore} ne "" ) { my $soonestrenewal = - $itemissue->{date_due}->clone() + $issue->{date_due}->clone() ->subtract( $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} ); diff --git a/circ/renew.pl b/circ/renew.pl index 42b7c3c..17d207f 100755 --- a/circ/renew.pl +++ b/circ/renew.pl @@ -78,8 +78,11 @@ if ($barcode) { if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) { $soonest_renew_date = C4::Circulation::GetSoonestRenewDate( - $borrower->borrowernumber(), - $item->itemnumber(), + { + borrower => $borrower->unblessed, + item => $item->unblessed, + issue => $issue->unblessed, + } ); } if ( $error && ( $error eq 'auto_too_late' ) ) { diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 413c26d..8d23d91 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -206,11 +206,16 @@ if ($issues){ $issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon'; if ( $renewerror eq 'too_soon' ) { + my $patron = C4::Members::GetMember( borrowernumber => $borrowernumber ); + my $item = C4::Items::GetItem( $issue->{itemnumber} ); $issue->{'too_soon'} = 1; $issue->{'soonestrenewdate'} = output_pref( C4::Circulation::GetSoonestRenewDate( - $issue->{borrowernumber}, - $issue->{itemnumber} + { + patron => $patron, + issue => $issue, + item => $item, + } ) ); } diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 38402f3..381df82 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -487,9 +487,11 @@ C4::Context->dbh->do("DELETE FROM accountlines"); # Bug 14395 # Test 'exact time' setting for syspref NoRenewalBeforePrecision + my $item = C4::Items::GetItem( $itemnumber ); + my $itemissue = C4::Circulation::GetItemIssue($itemnumber); t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' ); is( - GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ), + GetSoonestRenewDate( { patron => $renewing_borrower, item => $item, issue => $itemissue, } ), $datedue->clone->add( days => -7 ), 'Bug 14395: Renewals permitted 7 days before due date, as expected' ); @@ -498,7 +500,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); # Test 'date' setting for syspref NoRenewalBeforePrecision t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' ); is( - GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ), + GetSoonestRenewDate( { patron => $renewing_borrower, item => $item, issue => $itemissue, } ), $datedue->clone->add( days => -7 )->truncate( to => 'day' ), 'Bug 14395: Renewals permitted 7 days before due date, as expected' ); @@ -666,7 +668,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); LostItem( $itemnumber, 1 ); - my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber); + $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber); ok( !$item->onloan(), "Lost item marked as returned has false onloan value" ); my $total_due = $dbh->selectrow_array( -- 2.7.0