@@ -, +, @@ +finedays is in days, so hourly loans must multiply by 24 +grace period is measured in the same units as the loan DateTime::Duration->new( $unit => $issuingrule->{firstremind} ); DateTime::Duration->new( days => $issuingrule->{firstremind} ); --- C4/Circulation.pm | 11 +++----- .../Circulation/IssuingRules/maxsuspensiondays.t | 31 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 8 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2236,21 +2236,18 @@ sub _debar_user_on_return { ); my $finedays = $issuing_rule ? $issuing_rule->finedays : undef; my $unit = $issuing_rule ? $issuing_rule->lengthunit : undef; - my $chargeable_units = C4::Overdues::get_chargeable_units($unit, $dt_due, $return_date, $branchcode); if ($finedays) { - # finedays is in days, so hourly loans must multiply by 24 - # thus 1 hour late equals 1 day suspension * finedays rate - $finedays = $finedays * 24 if ( $unit eq 'hours' ); - # grace period is measured in the same units as the loan my $grace = DateTime::Duration->new( $unit => $issuing_rule->firstremind ); - my $deltadays = DateTime::Duration->new( - days => $chargeable_units + my $deltadays = C4::Overdues::get_chargeable_units('days', $dt_due, $return_date, $branchcode); + $deltadays = DateTime::Duration->new( + days => $deltadays, ); + if ( $deltadays->subtract($grace)->is_positive() ) { my $suspension_days = $deltadays * $finedays; --- a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t +++ a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t @@ -1,5 +1,5 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use MARC::Record; use MARC::Field; @@ -101,4 +101,33 @@ is( ); DelDebarment( $debarments->[0]->{borrower_debarment_id} ); +# Test with lengthunit => 'hours' +Koha::IssuingRules->search->delete; +$builder->build( + { + source => 'Issuingrule', + value => { + categorycode => '*', + itemtype => '*', + branchcode => '*', + firstremind => 0, + finedays => 2, + lengthunit => 'hours', + suspension_chargeperiod => 1, + maxsuspensiondays => 100, + } + } +); + +$daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10)); +AddIssue( $borrower, $barcode, $daysago20 ); +AddReturn( $barcode, $branchcode ); +$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}}); +is( + $debarments->[0]->{expiration}, + output_pref({ dt => $daysafter40, dateformat => 'iso', dateonly => 1 }), + 'calculate suspension with lengthunit hours.' +); +DelDebarment( $debarments->[0]->{borrower_debarment_id} ); + $schema->storage->txn_rollback; --