From 052f88d77740c035205db0b4aeed8d256707c660 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 1 Aug 2017 14:54:36 -0300 Subject: [PATCH] Bug 16413: Change prototype of GetLatestAutoRenewDate Currently the 2 GetLatestAutoRenewDate and GetSoonestRenewDate subroutines takes $borrowernumber and $itemnumber in parameter. They refetch the patron, item and issue information but they already are available from where they are called. It would make sense to change the prototype of these 2 subroutines to accept the patron, item and issue information directly to avoid unnecessary refetches. --- C4/Circulation.pm | 26 +++++++++----------------- circ/renew.pl | 6 +++--- t/db_dependent/Circulation.t | 17 ++++++++++------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index fbc2134a15..af0c715a1d 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2992,11 +2992,10 @@ sub GetSoonestRenewDate { my $item = $params->{item} or return; my $issue = $params->{issue} or return; - my $branchcode = _GetCircControlBranch( $item, $patron->unblessed ); + my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( { categorycode => $patron->categorycode, - - itemtype => $item->{itype}, + itemtype => $item->effective_itemtype, branchcode => $branchcode } ); @@ -3023,7 +3022,7 @@ sub GetSoonestRenewDate { =head2 GetLatestAutoRenewDate - $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate({ patron => $patron, issue => $issue, item => $item }); + $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate({ patron => $patron, checkout => $checkout, item => $item }); Find out the latest possible auto renew date of a borrowed item. @@ -3031,7 +3030,7 @@ C<$borrower> is the patron who currencly has the item on loan. C<$item> is the item to renew. -C<$issue> is the issue to renew. +C<$checkout> is the checkout to renew. C<$GetLatestAutoRenewDate> returns the DateTime of the latest possible auto renew date, based on the value "No auto renewal after" and the "No auto @@ -3044,21 +3043,14 @@ or item cannot be found. sub GetLatestAutoRenewDate { my ( $params ) = @_; - my $patron = $params->{patron} or return; + my $patron = $params->{patron} or return; my $item = $params->{item} or return; - my $issue = $params->{issue} or return; - - my $item = GetItem($itemnumber) or return; - my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; + my $checkout = $params->{checkout} or return; - $borrowernumber ||= $itemissue->borrowernumber; - my $patron = Koha::Patrons->find( $borrowernumber ) - or return; - - my $branchcode = _GetCircControlBranch( $item, $patron->unblessed ); + my $branchcode = _GetCircControlBranch( $item->unblessed, { branchcode => $patron->branchcode } ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( { categorycode => $patron->categorycode, - itemtype => $item->{itype}, + itemtype => $item->effective_itemtype, branchcode => $branchcode } ); @@ -3072,7 +3064,7 @@ sub GetLatestAutoRenewDate { my $maximum_renewal_date; if ( $issuing_rule->no_auto_renewal_after ) { - $maximum_renewal_date = dt_from_string($itemissue->issuedate); + $maximum_renewal_date = dt_from_string($checkout->issuedate); $maximum_renewal_date->add( $issuing_rule->lengthunit => $issuing_rule->no_auto_renewal_after ); diff --git a/circ/renew.pl b/circ/renew.pl index 32bc4b0d28..cfff2d76e4 100755 --- a/circ/renew.pl +++ b/circ/renew.pl @@ -90,9 +90,9 @@ if ($barcode) { if ( $error && ( $error eq 'auto_too_late' ) ) { $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate( { - patron => $borrower->unblessed, - item => $item->unblessed, - issue => $issue->unblessed, + patron => $borrower, + item => $item, + issue => $issue, } ); } diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 3acc8123ce..f84d0cbb0a 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -694,36 +694,39 @@ C4::Context->dbh->do("DELETE FROM accountlines"); } ); + my $renewing_borrower_obj = Koha::Patrons->find( $renewing_borrowernumber ); + my $item_to_auto_renew_obj = Koha::Items->find( $item_to_auto_renew->{itemnumber} ); + my $ten_days_before = dt_from_string->add( days => -10 ); my $ten_days_ahead = dt_from_string->add( days => 10 ); - my $issue = AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); - $issue->result_class('DBIx::Class::ResultClass::HashRefInflator'); + my $issue = AddIssue( $renewing_borrower, $item_to_auto_renew_obj->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); + $issue = Koha::Checkouts->find( $issue->issue_id ); $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = NULL'); - my $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } ); + my $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue, } ); is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' ); my $five_days_before = dt_from_string->add( days => -5 ); $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL'); - $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } ); + $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue }, ); is( $latest_auto_renew_date->truncate( to => 'minute' ), $five_days_before->truncate( to => 'minute' ), 'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' ); my $five_days_ahead = dt_from_string->add( days => 5 ); $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL'); - $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } ); + $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue }, ); is( $latest_auto_renew_date->truncate( to => 'minute' ), $five_days_ahead->truncate( to => 'minute' ), 'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' ); my $two_days_ahead = dt_from_string->add( days => 2 ); $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) ); - $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } ); + $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue }, ); is( $latest_auto_renew_date->truncate( to => 'day' ), $two_days_ahead->truncate( to => 'day' ), 'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' ); $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) ); - $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } ); + $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue }, ); is( $latest_auto_renew_date->truncate( to => 'day' ), $two_days_ahead->truncate( to => 'day' ), 'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after' -- 2.11.0