From 56df3a150b93f1c5a5e96622ca0a6837b7ceca78 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 --- C4/Circulation.pm | 7 ++++++- opac/opac-renew.pl | 2 +- t/db_dependent/Circulation/issue.t | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 1cfa69b..7e416ec 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2861,6 +2861,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; @@ -2963,10 +2964,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 03c4a71..90f3726 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 22f4d0a..eca5c12 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,21 @@ 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.1.4