Bug 16387: Fix default shortened loan period time
authorLari Taskula <lari.taskula@jns.fi>
Mon, 12 Dec 2016 14:49:44 +0000 (16:49 +0200)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 7 Feb 2017 17:54:21 +0000 (17:54 +0000)
When a loan period is shortened due to using decreaseLoanHighHolds* the time is
always set to the current time in X days, even if the original loan period is
given in days and not in hours.

It should default to 23:59 as is normal for loan periods given in days.

As original due date time defaults to 23:59 when given in days, this patch
modifies the hours and minutes of shortened due date to be equal to original due
date.

To test:
1. prove t/db_dependent/DecreaseLoanHighHolds.t

Signed-off-by: Grace McKenzie <grace.mcky@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

C4/Circulation.pm
t/db_dependent/DecreaseLoanHighHolds.t

index 0230429..e2cd626 100644 (file)
@@ -1219,6 +1219,9 @@ sub checkHighHolds {
         my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
 
         my $reduced_datedue = $calendar->addDate( $issuedate, $decreaseLoanHighHoldsDuration );
+        $reduced_datedue->set_hour($orig_due->hour);
+        $reduced_datedue->set_minute($orig_due->minute);
+        $reduced_datedue->truncate( to => 'minute' );
 
         if ( DateTime->compare( $reduced_datedue, $orig_due ) == -1 ) {
             $return_data->{exceeded} = 1;
index b6a175c..d4faaa3 100755 (executable)
@@ -27,7 +27,7 @@ use Koha::Hold;
 use t::lib::TestBuilder;
 use t::lib::Mocks;
 
-use Test::More tests => 14;
+use Test::More tests => 17;
 
 my $dbh    = C4::Context->dbh;
 my $schema = Koha::Database->new()->schema();
@@ -104,6 +104,13 @@ $builder->build(
 my $item   = pop(@items);
 my $patron = pop(@patrons);
 
+my $orig_due = C4::Circulation::CalcDateDue(
+    DateTime->now(time_zone => C4::Context->tz()),
+    $item->effective_itemtype,
+    $patron->branchcode,
+    $patron->unblessed
+);
+
 t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
 t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration',       1 );
 t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue',          1 );
@@ -119,6 +126,11 @@ is( $data->{outstanding},     6,          "Should have 5 outstanding holds" );
 is( $data->{duration},        1,          "Should have duration of 1" );
 is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
 
+my $duedate = $data->{due_date};
+is($duedate->hour, $orig_due->hour, 'New due hour is equal to original due hour.');
+is($duedate->min, $orig_due->min, 'New due minute is equal to original due minute.');
+is($duedate->sec, 0, 'New due date second is zero.');
+
 t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' );
 $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
 is( $data->{exceeded}, 0, "Should not exceed threshold" );