From 6ba23f113dc40e90cdef9e1e6a620ec2bb9ae06e Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Wed, 25 Apr 2018 16:15:42 -0400 Subject: [PATCH] Bug 17015: Updated patch after bug 19204 This is a small modification to bring the patch up-to-date with current master after the changes made in 19204. Tests in db_dependent/Circulation.thave been changed slightly since DiscreteCalendar strictly prevents changing holidays in the past. This patch requires 20660. --- C4/Circulation.pm | 4 +-- Koha/DiscreteCalendar.pm | 2 +- t/db_dependent/Circulation.t | 74 +++++++++++++++++++++----------------------- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 191c2f1..5549bd5 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2250,10 +2250,10 @@ sub _debar_user_on_return { my $new_debar_dt; # Use the calendar or not to calculate the debarment date if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) { - my $calendar = Koha::Calendar->new( + my $calendar = Koha::DiscreteCalendar->new( { branchcode => $branchcode, days_mode => 'Calendar' - ); + } ); $new_debar_dt = $calendar->addDate( $return_date, $suspension_days ); } else { diff --git a/Koha/DiscreteCalendar.pm b/Koha/DiscreteCalendar.pm index 8dee776..1ea5b12 100644 --- a/Koha/DiscreteCalendar.pm +++ b/Koha/DiscreteCalendar.pm @@ -90,7 +90,7 @@ sub new { sub _init { my $self = shift; - $self->{days_mode} = C4::Context->preference('useDaysMode'); + $self->{days_mode} ||= C4::Context->preference('useDaysMode'); #If the branchcode doesn't exist we use the default calendar. my $schema = Koha::Database->new->schema; my $branchcode = $self->{branchcode}; diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 99d1ae0..04478e4 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -24,7 +24,6 @@ use POSIX qw( floor ); use t::lib::Mocks; use t::lib::TestBuilder; -use C4::Calendar; use C4::Circulation; use C4::Biblio; use C4::Items; @@ -34,6 +33,7 @@ use C4::Reserves; use C4::Overdues qw(UpdateFine CalcFine); use Koha::DateUtils; use Koha::Database; +use Koha::DiscreteCalendar; use Koha::IssuingRules; use Koha::Checkouts; use Koha::Patrons; @@ -1802,16 +1802,16 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { ); $rule->store(); - my $five_days_ago = dt_from_string->subtract( days => 5 ); + my $in_five_days = dt_from_string->add( days => 5 ); # We want to charge 2 days every day, without grace # With 5 days of overdue: 5 * Z - my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 ); + my $expected_expiration = dt_from_string->add( days => 5 + ( 5 * 2 ) / 1 ); test_debarment_on_checkout( { item => $item_1, library => $library, patron => $patron, - due_date => $five_days_ago, + return_date => $in_five_days, expiration_date => $expected_expiration, } ); @@ -1819,13 +1819,13 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { # We want to charge 2 days every 2 days, without grace # With 5 days of overdue: (5 * 2) / 2 $rule->suspension_chargeperiod(2)->store; - $expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 ); + $expected_expiration = dt_from_string->add( days => 5 + floor( 5 * 2 ) / 2 ); test_debarment_on_checkout( { item => $item_1, library => $library, patron => $patron, - due_date => $five_days_ago, + return_date => $in_five_days, expiration_date => $expected_expiration, } ); @@ -1834,13 +1834,13 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { # With 5 days of overdue: ((5-1) / 3 ) * 2 $rule->suspension_chargeperiod(3)->store; $rule->firstremind(1)->store; - $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); + $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); test_debarment_on_checkout( { item => $item_1, library => $library, patron => $patron, - due_date => $five_days_ago, + return_date => $in_five_days, expiration_date => $expected_expiration, } ); @@ -1853,65 +1853,63 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed'); # Adding a holiday 2 days ago - my $calendar = C4::Calendar->new(branchcode => $library->{branchcode}); - my $two_days_ago = dt_from_string->subtract( days => 2 ); - $calendar->insert_single_holiday( - day => $two_days_ago->day, - month => $two_days_ago->month, - year => $two_days_ago->year, - title => 'holidayTest-2d', - description => 'holidayDesc 2 days ago' - ); + my $calendar = Koha::DiscreteCalendar->new( { branchcode => $library->{branchcode} } ); + my $in_two_days = dt_from_string->add( days => 2 ); + $calendar->edit_holiday( { + title => 'holidayTest+2d', + holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},, + start_date => $in_two_days, + end_date => $in_two_days, + } ); # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) - $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); + $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); test_debarment_on_checkout( { item => $item_1, library => $library, patron => $patron, - due_date => $five_days_ago, + return_date => $in_five_days, expiration_date => $expected_expiration, } ); # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped - my $two_days_ahead = dt_from_string->add( days => 2 ); - $calendar->insert_single_holiday( - day => $two_days_ahead->day, - month => $two_days_ahead->month, - year => $two_days_ahead->year, - title => 'holidayTest+2d', - description => 'holidayDesc 2 days ahead' - ); + my $in_seven_days = dt_from_string->add( days => 7 ); + $calendar->edit_holiday( { + title => 'holidayTest+7d', + holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, + start_date => $in_seven_days, + end_date => $in_seven_days, + } ); # Same as above, but we should skip D+2 - $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); + $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); test_debarment_on_checkout( { item => $item_1, library => $library, patron => $patron, - due_date => $five_days_ago, + return_date => $in_five_days, expiration_date => $expected_expiration, } ); # Adding another holiday, day of expiration date my $expected_expiration_dt = dt_from_string($expected_expiration); - $calendar->insert_single_holiday( - day => $expected_expiration_dt->day, - month => $expected_expiration_dt->month, - year => $expected_expiration_dt->year, - title => 'holidayTest_exp', - description => 'holidayDesc on expiration date' - ); + $calendar->edit_holiday( { + title => 'holidayTest+expected_expiration', + holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, + start_date => $expected_expiration_dt, + end_date => $expected_expiration_dt, + } ); + # Expiration date will be the day after test_debarment_on_checkout( { item => $item_1, library => $library, patron => $patron, - due_date => $five_days_ago, + return_date => $in_five_days, expiration_date => $expected_expiration_dt->clone->add( days => 1 ), } ); @@ -1922,7 +1920,7 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { library => $library, patron => $patron, return_date => dt_from_string->add(days => 5), - expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) ), + expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) + 1 ), # We add an extra +1 because of the holiday } ); }; -- 2.7.4