From bde8a23de6ccb72176dc888f0c3a31e39d724a87 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 31 Jan 2019 14:56:54 +0000
Subject: [PATCH] Bug 20912: (QA follow-up) Fix some test failures

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 C4/Circulation.pm                  |  6 ++----
 t/db_dependent/Circulation/issue.t | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index ce872f7a2e..cec20c820a 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -2886,8 +2886,7 @@ sub AddRenewal {
     my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
     my $patron_unblessed = $patron->unblessed;
 
-    my $library = Koha::Libraries->find( $branch );
-
+    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item, $patron_unblessed) );
 
     if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
         _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
@@ -2906,11 +2905,10 @@ sub AddRenewal {
         $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
     }
 
-
     my $fees = Koha::Charges::Fees->new(
         {
             patron    => $patron,
-            library   => $library,
+            library   => $circ_library,
             item      => $item_object,
             to_date   => dt_from_string( $datedue ),
         }
diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t
index 336323977b..47b90e35a1 100644
--- a/t/db_dependent/Circulation/issue.t
+++ b/t/db_dependent/Circulation/issue.t
@@ -84,6 +84,22 @@ my $categorycode = $builder->build({
         value => { enrolmentfee => undef }
     })->{categorycode};
 
+# A default issuingrule should always be present
+my $issuingrule = $builder->build(
+    {
+        source => 'Issuingrule',
+        value  => {
+            itemtype      => '*',
+            categorycode  => '*',
+            branchcode    => '*',
+            lengthunit    => 'days',
+            issuelength   => 0,
+            renewalperiod => 0,
+            renewalsallowed => 0
+        }
+    }
+);
+
 # Add Dates
 my $dt_today = dt_from_string;
 my $today    = output_pref(
-- 
2.20.1