Bugzilla – Attachment 50743 Details for
Bug 15581
Add a circ rule to not allow auto-renewals after defined loan period
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15581: Display the latest auto renew date possible when renewing manually
0002-Bug-15581-Display-the-latest-auto-renew-date-possibl.patch (text/plain), 8.13 KB, created by
Martin Renvoize (ashimema)
on 2016-04-26 18:06:52 UTC
(
hide
)
Description:
Bug 15581: Display the latest auto renew date possible when renewing manually
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2016-04-26 18:06:52 UTC
Size:
8.13 KB
patch
obsolete
>From 78a6929f3714066f14b5fcaf250eb8899d3ed1c3 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 14 Jan 2016 14:38:23 +0000 >Subject: [PATCH 2/4] Bug 15581: Display the latest auto renew date possible > when renewing manually > >If an issue marked as auto_renew is renewed manually, we want to display >the latest auto renew date possible. > >Test plan: >1/ Define circ rules as in the previous patch. >2/ Check a item out, mark it as an auto renewal >3/ Back date the issuedate and make sure it will be too late to renew it >4/ Use the Circulation > renew page (circ/renew.pl) to manually renew >this issue. >You should get a warning "You barcode has been scheduled for automatic renewal >and cannot be renewed anymore since DATE." >If the pref AllowRenewalLimitOverride is set, you will be allowed to >renew it anyway. > >Sponsored-by: University of the Arts London >Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com> >--- > C4/Circulation.pm | 50 ++++++++++++++++++++ > circ/renew.pl | 9 +++- > .../intranet-tmpl/prog/en/modules/circ/renew.tt | 2 +- > t/db_dependent/Circulation.t | 36 +++++++++++++- > 4 files changed, 94 insertions(+), 3 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index ce59bf2..63e7ce3 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -86,6 +86,7 @@ BEGIN { > &AddRenewal > &GetRenewCount > &GetSoonestRenewDate >+ &GetLatestAutoRenewDate > &GetItemIssue > &GetItemIssues > &GetIssuingCharges >@@ -3171,6 +3172,55 @@ sub GetSoonestRenewDate { > return $now; > } > >+=head2 GetLatestAutoRenewDate >+ >+ $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate($borrowernumber, $itemnumber); >+ >+Find out the latest possible auto renew date of a borrowed item. >+ >+C<$borrowernumber> is the borrower number of the patron who currently >+has the item on loan. >+ >+C<$itemnumber> is the number of the item to renew. >+ >+C<$GetLatestAutoRenewDate> returns the DateTime of the latest possible >+auto renew date, based on the value "No auto renewal after" of the applicable >+issuing rule. >+Returns undef if there is no date specify in the circ rules or if the patron, loan, >+or item cannot be found. >+ >+=cut >+ >+sub GetLatestAutoRenewDate { >+ my ( $borrowernumber, $itemnumber ) = @_; >+ >+ my $dbh = C4::Context->dbh; >+ >+ my $item = GetItem($itemnumber) or return; >+ my $itemissue = GetItemIssue($itemnumber) or return; >+ >+ $borrowernumber ||= $itemissue->{borrowernumber}; >+ my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) >+ or return; >+ >+ my $branchcode = _GetCircControlBranch( $item, $borrower ); >+ my $issuingrule = >+ GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode ); >+ >+ my $now = dt_from_string; >+ >+ return if not $issuingrule->{no_auto_renewal_after} >+ or $issuingrule->{no_auto_renewal_after} eq ''; >+ >+ my $maximum_renewal_date = dt_from_string($itemissue->{issuedate}); >+ $maximum_renewal_date->add( >+ $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after} >+ ); >+ >+ return $maximum_renewal_date; >+} >+ >+ > =head2 GetIssuingCharges > > ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber); >diff --git a/circ/renew.pl b/circ/renew.pl >index a87ba76..2b4114e 100755 >--- a/circ/renew.pl >+++ b/circ/renew.pl >@@ -47,7 +47,7 @@ my $override_holds = $cgi->param('override_holds'); > > my ( $item, $issue, $borrower ); > my $error = q{}; >-my $soonest_renew_date; >+my ( $soonest_renew_date, $latest_auto_renew_date ); > > if ($barcode) { > $item = $schema->resultset("Item")->single( { barcode => $barcode } ); >@@ -82,6 +82,12 @@ if ($barcode) { > $item->itemnumber(), > ); > } >+ if ( $error && ( $error eq 'auto_too_late' ) ) { >+ $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate( >+ $borrower->borrowernumber(), >+ $item->itemnumber(), >+ ); >+ } > if ($can_renew) { > my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; > my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode ); >@@ -106,6 +112,7 @@ if ($barcode) { > borrower => $borrower, > error => $error, > soonestrenewdate => $soonest_renew_date, >+ latestautorenewdate => $latest_auto_renew_date, > ); > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt >index 80b8971..1d4785c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt >@@ -79,7 +79,7 @@ > > [% ELSIF error == "auto_too_late" %] > >- <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal and cannot be renewed since [% latestrenewdate | $KohaDates %]. </p> >+ <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal and cannot be renewed anymore since [% latestautorenewdate | $KohaDates %]. </p> > > [% IF Koha.Preference('AllowRenewalLimitOverride') %] > <form method="post" action="/cgi-bin/koha/circ/renew.pl"> >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index 8ad6075..afbe8a8 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -30,7 +30,7 @@ use Koha::Database; > > use t::lib::TestBuilder; > >-use Test::More tests => 83; >+use Test::More tests => 84; > > BEGIN { > use_ok('C4::Circulation'); >@@ -573,6 +573,40 @@ C4::Context->dbh->do("DELETE FROM accountlines"); > is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); > }; > >+ subtest "GetLatestAutoRenewDate" => sub { >+ plan tests => 3; >+ my $item_to_auto_renew = $builder->build( >+ { source => 'Item', >+ value => { >+ biblionumber => $biblionumber, >+ homebranch => $branch, >+ holdingbranch => $branch, >+ } >+ } >+ ); >+ >+ my $ten_days_before = dt_from_string->add( days => -10 ); >+ my $ten_days_ahead = dt_from_string->add( days => 10 ); >+ AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); >+ $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""'); >+ my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); >+ is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' ); >+ my $five_days_before = dt_from_string->add( days => -5 ); >+ $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5'); >+ $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); >+ 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'); >+ $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); >+ 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' >+ ); >+ }; >+ > # Too many renewals > > # set policy to forbid renewals >-- >1.7.10.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15581
:
46690
|
46691
|
46692
|
50330
|
50331
|
50332
|
50347
|
50672
|
50673
|
50674
|
50675
|
50742
|
50743
|
50744
|
50745
|
53424
|
53425
|
53426
|
53427
|
55504
|
55505
|
55506
|
55507
|
56746
|
56747
|
56748
|
56749
|
56961
|
56962
|
56963
|
56964
|
56982
|
57034
|
57035
|
57036
|
57037
|
57038