From b6348c78d930ae320e4874fc379ea717f192b8b8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Feb 2019 17:49:21 -0300 Subject: [PATCH] Bug 18936: new suspension_chargeperiod --- C4/Circulation.pm | 5 +++-- Koha/CirculationRules.pm | 3 +++ t/db_dependent/Circulation.t | 41 ++++++++++++++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index d83e3bf4f8..ae535de424 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2250,6 +2250,7 @@ sub _debar_user_on_return { 'lengthunit', 'firstremind', 'maxsuspensiondays', + 'suspension_chargeperiod', ] } ); @@ -2291,10 +2292,10 @@ sub _debar_user_on_return { } } - if ( $issuing_rule->suspension_chargeperiod > 1 ) { + if ( $issuing_rule->{suspension_chargeperiod} > 1 ) { # No need to / 1 and do not consider / 0 $suspension_days = DateTime::Duration->new( - days => floor( $suspension_days->in_units('days') / $issuing_rule->suspension_chargeperiod ) + days => floor( $suspension_days->in_units('days') / $issuing_rule->{suspension_chargeperiod} ) ); } diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 2f6da8816d..9d38f19a16 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -148,6 +148,9 @@ our $RULE_KINDS = { reservesallowed => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, + suspension_chargeperiod => { + scope => [ 'branchcode', 'categorycode', 'itemtype' ], + }, # Not included (deprecated?): # * accountsent # * reservecharge diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 496a7dd6b0..a67c36bbf0 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -2089,7 +2089,16 @@ 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; + Koha::CirculationRules->set_rule( + { + categorycode => undef, + branchcode => undef, + itemtype => undef, + rule_name => 'suspension_chargeperiod', + rule_value => '2', + } + ); + $expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 ); test_debarment_on_checkout( { @@ -2103,8 +2112,17 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { # We want to charge 2 days every 3 days, with 1 day of grace # With 5 days of overdue: ((5-1) / 3 ) * 2 - $rule->suspension_chargeperiod(3)->store; - $rule->firstremind(1)->store; + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => undef, + itemtype => undef, + rules => { + suspension_chargeperiod => 3, + firstremind => 1, + } + } + ); $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); test_debarment_on_checkout( { @@ -2118,9 +2136,18 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { # Use finesCalendar to know if holiday must be skipped to calculate the due date # We want to charge 2 days every days, with 0 day of grace (to not burn brains) - $rule->finedays(2)->store; - $rule->suspension_chargeperiod(1)->store; - $rule->firstremind(0)->store; + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => undef, + itemtype => undef, + rules => { + finedays => 2, + suspension_chargeperiod => 1, + firstremind => 0, + } + } + ); t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed'); # Adding a holiday 2 days ago @@ -2297,7 +2324,7 @@ subtest 'AddReturn | is_overdue' => sub { ); Koha::CirculationRules->search->delete; - my $rule = Koha::CirculationRules->set_rules( + Koha::CirculationRules->set_rules( { categorycode => undef, itemtype => undef, -- 2.11.0