From d8722dde9b028adbda9d46f9c181713eb0615052 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 --- C4/Circulation.pm | 7 ++++++- opac/opac-renew.pl | 2 +- t/db_dependent/Circulation/issue.t | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 8e852fc4fa..0d499d5ee2 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2848,6 +2848,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; @@ -2950,10 +2951,14 @@ sub AddRenewal { DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); } + 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 03c4a714a4..90f3726588 100755 --- a/opac/opac-renew.pl +++ b/opac/opac-renew.pl @@ -83,7 +83,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 22f4d0a32b..a14af7c5a1 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; @@ -230,6 +230,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