From d3ebbb88be68e42318f3de08ba55318e2970a70c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 18 Apr 2022 17:54:14 -0300 Subject: [PATCH] Bug 22456: Add waiting_hold_cancellation circulation rule This patch adds handling for the waiting_hold_cancellation circulation rule. It is set no 'No' by default in the atomic update, if not previously set. Handling in the rules editor is added, in its own section. To test: 1. Apply this patch 2. Run: $ updatedatabase => SUCCESS: All good 3. Verify that the syspref is set: $ koha-mysql kohadev > SELECT * FROM circulation_rules WHERE rule_name='waiting_hold_cancellation'; => SUCCESS: Set to 0 4. Play with the rules editor, changing things back and forth, things should work, including library-specific and global/defualt settings. => SUCCESS: It works => SUCCESS: Texts are idiomatic 5. Sign off :-D Sponsored-by: Montgomery County Public Libraries Signed-off-by: David Nind Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/CirculationRules.pm | 4 + admin/smart-rules.pl | 33 ++++++++ .../data/mysql/atomicupdate/bug_22456.pl | 16 ++++ .../prog/en/modules/admin/smart-rules.tt | 83 +++++++++++++++++++ 4 files changed, 136 insertions(+) diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 81590785e3..b9fc11c941 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -112,6 +112,10 @@ our $RULE_KINDS = { hardduedatecompare => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, + waiting_hold_cancellation => { + scope => [ 'branchcode', 'categorycode', 'itemtype' ], + can_be_blank => 0, + }, holds_per_day => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index b7f2ae643e..d8fffaf924 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -660,8 +660,41 @@ elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { } ); } +} elsif ( $op eq "set-waiting-hold-cancellation" ) { + + my $category = $input->param('waiting_hold_cancellation_category'); + my $itemtype = $input->param('waiting_hold_cancellation_itemtype'); + my $policy = strip_non_numeric( scalar $input->param('waiting_hold_cancellation_policy') ) + ? 1 + : 0; + + Koha::Exception->throw("No value passed for waiting holds cancellation policy") + if not defined $policy # There is a JS check for that + || $policy eq ''; + + Koha::CirculationRules->set_rules( + { categorycode => ( $category eq '*' ) ? undef : $category, + itemtype => ( $itemtype eq '*' ) ? undef : $itemtype, + branchcode => ( $branch eq '*' ) ? undef : $branch, + rules => { waiting_hold_cancellation => $policy }, + } + ); + +} elsif ( $op eq 'del-waiting-hold-cancellation' ) { + + my $category = $input->param('waiting_hold_cancellation_category'); + my $itemtype = $input->param('waiting_hold_cancellation_itemtype'); + + Koha::CirculationRules->set_rules( + { categorycode => ( $category eq '*' ) ? undef : $category, + itemtype => ( $itemtype eq '*' ) ? undef : $itemtype, + branchcode => ( $branch eq '*' ) ? undef : $branch, + rules => { waiting_hold_cancellation => undef }, + } + ); } + my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'lostreturn' }); my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'lostreturn' }); $template->param( diff --git a/installer/data/mysql/atomicupdate/bug_22456.pl b/installer/data/mysql/atomicupdate/bug_22456.pl index df6e42da84..d7cef277b2 100755 --- a/installer/data/mysql/atomicupdate/bug_22456.pl +++ b/installer/data/mysql/atomicupdate/bug_22456.pl @@ -17,5 +17,21 @@ return { ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; }); } + + my ($count) = $dbh->selectrow_array(q{ + SELECT COUNT(*) + FROM circulation_rules + WHERE rule_name = 'waiting_hold_cancellation' + }); + + unless ( $count ) { + $dbh->do(q{ + INSERT INTO circulation_rules (rule_name, rule_value) + VALUES ('waiting_hold_cancellation', 0) + }); + } + else { + say $out "Found already existing 'waiting_hold_cancellation' circulation rules on the DB. Please review."; + } }, }; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 1e8bc8907e..6727885768 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -845,6 +845,89 @@ [% END %] +
+ [% IF humanbranch %] +

Waiting hold cancellation policy for [% Branches.GetName( humanbranch ) | html %]

+ [% ELSE %] +

Default waiting hold cancellation policy

+ [% END %] +

Specify if waiting holds can be cancelled for a given patron category.

+
+ + + + + + + + + + [% FOREACH c IN categorycodes %] + [% SET c = '*' UNLESS c.defined AND c != '' %] + [% FOREACH i IN itemtypes %] + [% SET i = '*' UNLESS i.defined AND i != '' %] + + [% SET waiting_hold_cancellation = CirculationRules.Search( current_branch, c, i, 'waiting_hold_cancellation' ) %] + + [% IF ( waiting_hold_cancellation.defined && waiting_hold_cancellation != '' ) %] + + + + + + + [% END %] + [% END %] + [% END %] + + + + + + +
Patron categoryItem typeCancellation allowed 
+ [% IF c == '*' %] + All + [% ELSE %] + [% Categories.GetName(c) | html %] + [% END %] + + [% IF i == '*' %] + All + [% ELSE %] + [% ItemTypes.GetDescription(i,1) | html %] + [% END %] + + [% IF waiting_hold_cancellation %] + Yes + [% ELSE %] + No + [% END %] + + Delete +
+ + + + + +
+
+
+ [% IF Koha.Preference('ArticleRequests') %]
[% IF humanbranch %] -- 2.39.5