From 2a4f00c0c8036de0effcd6db1d235fed61c3e9b7 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 --- 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 fbfbe2e6ec..f77ffc3bb2 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -110,6 +110,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 3d094a5fdb..611e8da7e6 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 62e2f5639a..fa33a678ce 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 @@ -836,6 +836,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.34.1