@@ -, +, @@ --- C4/Circulation.pm | 22 +++++++++++++++++++--- Koha/CirculationRules.pm | 3 +++ admin/smart-rules.pl | 2 ++ .../bug_14866-add_decreaseloanholds_circrule.perl | 6 ++++++ installer/onboarding.pl | 1 + .../prog/en/modules/admin/smart-rules.tt | 7 ++++++- t/db_dependent/DecreaseLoanHighHolds.t | 16 +++++++++++++++- 7 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_14866-add_decreaseloanholds_circrule.perl --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -1244,15 +1244,31 @@ sub checkHighHolds { my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower ); my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration'); - - my $reduced_datedue = $calendar->addDate( $issuedate, $decreaseLoanHighHoldsDuration ); + my $rule = Koha::CirculationRules->get_effective_rule( + { + categorycode => $borrower->{categorycode}, + itemtype => $item_object->effective_itemtype, + branchcode => $branchcode, + rule_name => 'decreaseloanholds', + } + ); + my $reduced_datedue; + my $duration; + if ( defined($rule->rule_value) && $rule->rule_value > 0 ){ + $duration = $rule->rule_value; + # overrides decreaseLoanHighHoldsDuration syspref + $reduced_datedue = $calendar->addDate( $issuedate, $rule->rule_value ); + } else { + $duration = $decreaseLoanHighHoldsDuration; + $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; - $return_data->{duration} = $decreaseLoanHighHoldsDuration; + $return_data->{duration} = $duration; $return_data->{due_date} = $reduced_datedue; } } --- a/Koha/CirculationRules.pm +++ a/Koha/CirculationRules.pm @@ -157,6 +157,9 @@ our $RULE_KINDS = { note => { # This is not really a rule. Maybe we will want to separate this later. scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, + decreaseloanholds => { + scope => [ 'branchcode', 'categorycode', 'itemtype' ], + }, # Not included (deprecated?): # * accountsent # * reservecharge --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -288,6 +288,7 @@ elsif ($op eq 'add') { my $overduefinescap = $input->param('overduefinescap') || ''; my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on'; my $note = $input->param('note'); + my $decreaseloanholds = $input->param('decreaseloanholds') || undef; $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price"; my $rules = { @@ -320,6 +321,7 @@ elsif ($op eq 'add') { cap_fine_to_replacement_price => $cap_fine_to_replacement_price, article_requests => $article_requests, note => $note, + decreaseloanholds => $decreaseloanholds, }; Koha::CirculationRules->set_rules( --- a/installer/data/mysql/atomicupdate/bug_14866-add_decreaseloanholds_circrule.perl +++ a/installer/data/mysql/atomicupdate/bug_14866-add_decreaseloanholds_circrule.perl @@ -0,0 +1,6 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{INSERT IGNORE INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value) VALUES (NULL, NULL, NULL, 'decreaseloanholds', '0') }); + + NewVersion( $DBversion, 14866, "Add decreaseloanholds circulation rule" ); +} --- a/installer/onboarding.pl +++ a/installer/onboarding.pl @@ -283,6 +283,7 @@ if ( $step == 5 ) { rentaldiscount => 0, reservesallowed => $reservesallowed, suspension_chargeperiod => undef, + decreaseloanholds => undef, } }; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -117,6 +117,7 @@ OPAC item level holds Article requests Rental discount (%) + Decrease loan holds (day) Actions @@ -155,8 +156,9 @@ [% SET opacitemholds = all_rules.$c.$i.opacitemholds %] [% SET article_requests = all_rules.$c.$i.article_requests %] [% SET rentaldiscount = all_rules.$c.$i.rentaldiscount %] + [% SET decreaseloanholds = all_rules.$c.$i.decreaseloanholds %] - [% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %] + [% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests || decreaseloanholds %] [% IF show_rule %] [% SET row_count = row_count + 1 %] @@ -301,6 +303,7 @@ [% END %] [% rentaldiscount | html %] + [% decreaseloanholds | html %] Edit Delete @@ -404,6 +407,7 @@ + @@ -443,6 +447,7 @@ OPAC item level holds Article requests Rental discount (%) + Decrease loan holds (day)   --- a/t/db_dependent/DecreaseLoanHighHolds.t +++ a/t/db_dependent/DecreaseLoanHighHolds.t @@ -30,7 +30,7 @@ use Koha::CirculationRules; use t::lib::TestBuilder; use t::lib::Mocks; -use Test::More tests => 17; +use Test::More tests => 18; my $dbh = C4::Context->dbh; my $schema = Koha::Database->new()->schema(); @@ -106,6 +106,7 @@ Koha::CirculationRules->set_rules( lengthunit => 'days', reservesallowed => '99', holds_per_record => '99', + decreaseloanholds => 0, } } ); @@ -197,4 +198,17 @@ ok( $needsconfirmation->{HIGHHOLDS}, "High holds checkout needs confirmation" ); ( undef, $needsconfirmation ) = CanBookBeIssued( $patron_object, $item->barcode, undef, undef, undef, { override_high_holds => 1 } ); ok( !$needsconfirmation->{HIGHHOLDS}, "High holds checkout does not need confirmation" ); +Koha::CirculationRules->set_rule( + { + branchcode => undef, + categorycode => undef, + itemtype => $item->itype, + rule_name => 'decreaseloanholds', + rule_value => 2, + } +); + +$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); +is( $data->{duration}, 2, "Circulation rules override system preferences" ); + $schema->storage->txn_rollback(); --