From 996ffc950d3a9890711aec106ca6fb1f01f0b47d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 10 Mar 2021 15:44:20 +0000 Subject: [PATCH] Bug 27835: Do not count closed day if holiday when calculating fines Bug 27180 attempted to allow calculating fines on holidays when the calendar was ignored but it affected the day when an item would be charged when following the calendar for fines The difference seems to be that get_chargeable_units returns 1 if the start date is yesterday and today is a holiday. If finesCalendar is set to 'noFinesWhenClosed' then there should be 0 chargable units To test: 1 - Checkout an item to a patron, due yesterday 2 - Confirm the circ rules are set to charge .1 per 1 day 3 - perl misc/cronjobs/fines.pl -v 4 - Patron is charged .1 5 - Clear the checkout and fine and recreate 6 - Apply patch 7 - perl misc/cronjobs/fines.pl -v 8 - Patron is charged 0 9 - prove -v t/db_dependent/Circulation/CalcFine.t --- C4/Overdues.pm | 1 + t/db_dependent/Circulation/CalcFine.t | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index d484c67b0f..af15f0a6c7 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -318,6 +318,7 @@ sub get_chargeable_units { if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { my $calendar = Koha::Calendar->new( branchcode => $branchcode ); $charge_duration = $calendar->days_between( $date_due, $date_returned ); + $charge_duration->subtract(days=>1) if $calendar->is_holiday( $date_returned ); } else { $charge_duration = $date_returned->delta_days( $date_due ); } diff --git a/t/db_dependent/Circulation/CalcFine.t b/t/db_dependent/Circulation/CalcFine.t index 85f38ea42e..c56882bc01 100755 --- a/t/db_dependent/Circulation/CalcFine.t +++ b/t/db_dependent/Circulation/CalcFine.t @@ -4,6 +4,7 @@ use Modern::Perl; use Test::More tests => 3; +use C4::Calendar; use C4::Context; use C4::Overdues; @@ -62,7 +63,9 @@ my $item = $builder->build_sample_item( ); subtest 'Test basic functionality' => sub { - plan tests => 1; + plan tests => 3; + + t::lib::Mocks::mock_preference('finesCalendar', 'ignoreCalendar'); Koha::CirculationRules->set_rules( { @@ -97,6 +100,15 @@ subtest 'Test basic functionality' => sub { is( $amount, 29, 'Amount is calculated correctly' ); + + C4::Calendar->new(branchcode=>$branch->{branchcode})->insert_single_holiday(date=>'2000-01-30',title=>'test',description=>'test'); + ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); + is( $amount, 29, 'Amount is calculated correctly ignoring holidays' ); + + t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed'); + ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); + is( $amount, 28, 'Amount is calculated correctly excluding holidays' ); + teardown(); }; -- 2.11.0