From 88fba552c6a5d44ee42466d1ae36a1081f4daef5 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 23 Jun 2017 12:27:19 +0000 Subject: [PATCH] Bug 18572 - Improper branchcode set during OPAC renewal To test: 1 - Set 'OpacRenewalBranch' to various settings 2 - Renew an item for a ptron under each setting 3 - Confirm action_log entries reflect the correct branch for each secnario 4 - prove t/db_dependent/Circulation/issue.t Signed-off-by: David Kuhn Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart (cherry picked from commit e9374dcf6308256f4597e1c83920559d2673b90c) Signed-off-by: Fridolin Somers (cherry picked from commit d8722dde9b028adbda9d46f9c181713eb0615052) Signed-off-by: Katrin Fischer --- C4/Circulation.pm | 9 +++++++-- opac/opac-renew.pl | 2 +- t/db_dependent/Circulation/issue.t | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 77055d66b0..95ba55e019 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2926,6 +2926,7 @@ sub AddRenewal { my $branch = shift; my $datedue = shift; my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd(); + my $opacrenewal = shift; my $item = GetItem($itemnumber) or return; my $biblio = GetBiblioFromItemNumber($itemnumber) or return; @@ -3028,10 +3029,14 @@ sub AddRenewal { DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); } - # Log the renewal + unless ( $opacrenewal ) { #if from opac we are obeying OpacRenewalBranch as calculated in opac-renew.pl + $branch = C4::Context->userenv ? C4::Context->userenv->{branch} : $branch; + } + + # Add the renewal to stats UpdateStats( { - branch => C4::Context->userenv ? C4::Context->userenv->{branch} : $branch, + branch => $branch, type => 'renew', amount => $charge, itemnumber => $itemnumber, diff --git a/opac/opac-renew.pl b/opac/opac-renew.pl index 9da82e54f0..6435ea5435 100755 --- a/opac/opac-renew.pl +++ b/opac/opac-renew.pl @@ -82,7 +82,7 @@ else { else { $branchcode = 'OPACRenew'; } - AddRenewal( $borrowernumber, $itemnumber, $branchcode ); + AddRenewal( $borrowernumber, $itemnumber, $branchcode, undef, undef, 1 ); push( @renewed, $itemnumber ); } else { diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index e959ae81f4..17f596984f 100644 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 33; +use Test::More tests => 34; use DateTime::Duration; use t::lib::Mocks; @@ -231,6 +231,19 @@ like( my $stat = $dbh->selectrow_hashref("SELECT * FROM statistics WHERE type = 'renew' AND borrowernumber = ? AND itemnumber = ? AND branch = ?", undef, $borrower_id1, $item_id1, $branchcode_3 ); ok( $stat, "Bug 17781 - 'Improper branchcode set during renewal' still fixed" ); +#Let's do an opac renewal - whatever branchcode we send should be used +my $opac_renew_issue = $builder->build({ source=>"Issue",value=>{ + date_due => '2017-01-01', + branch => $branchcode_1, + itype => $itemtype, + borrowernumber => $borrower_id1 + } + }); + +my $datedue4 = AddRenewal( $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber}, "Stavromula", $datedue1, $daysago10, 1 ); + +$stat = $dbh->selectrow_hashref("SELECT * FROM statistics WHERE type = 'renew' AND borrowernumber = ? AND itemnumber = ? AND branch = ?", undef, $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber}, "Stavromula" ); +ok( $stat, "Bug 18572 - 'Bug 18572 - OpacRenewalBranch is now respected" ); #Test GetBiblioIssues is( GetBiblioIssues(), undef, "GetBiblio Issues without parameters" ); -- 2.39.5