Bug 23112: (follow-up) Conditionally prevent checkout
authorAndrew Isherwood <andrew.isherwood@ptfs-europe.com>
Thu, 5 Mar 2020 09:27:32 +0000 (09:27 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 10 Mar 2020 10:59:54 +0000 (10:59 +0000)
As mentioned by Nick in comment #69, the checkout button displays even
for requests without a biblio attached (such as chapters). This patch
fixes that.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Illrequest.pm
koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt

index c6280d2..a11ff86 100644 (file)
@@ -495,6 +495,8 @@ sub _core_status_graph {
             ui_method_name => 'Check out',
             needs_prefs    => [ 'CirculateILL' ],
             needs_perms    => [ 'user_circulate_circulate_remaining_permissions' ],
+            # An array of functions that all must return true
+            needs_all      => [ sub { my $r = shift;  return $r->biblio; } ],
             method         => 'check_out',
             next_actions   => [ ],
             ui_method_icon => 'fa-upload',
@@ -1049,6 +1051,25 @@ sub requires_moderation {
     return $require_moderation->{$self->status};
 }
 
+=head3 biblio
+
+    my $biblio = $request->biblio;
+
+For a given request, return the biblio associated with it,
+or undef if none exists
+
+=cut
+
+sub biblio {
+    my ( $self ) = @_;
+
+    return if !$self->biblio_id;
+
+    return Koha::Biblios->find({
+        biblionumber => $self->biblio_id
+    });
+}
+
 =head3 check_out
 
     my $stage_summary = $request->check_out;
@@ -1072,9 +1093,8 @@ sub check_out {
         {},
         { order_by => ['branchcode'] }
     );
-    my $biblio = Koha::Biblios->find({
-        biblionumber => $self->biblio_id
-    });
+    my $biblio = $self->biblio;
+
     # Find all statistical patrons
     my $statistical_patrons = Koha::Patrons->search(
         { 'category_type' => 'x' },
index 413e4a1..b5ccab4 100644 (file)
                         [% FOREACH action IN request.available_actions %]
                             [% needs_prefs = action.needs_prefs.size ? action.needs_prefs : [] %]
                             [% needs_perms = action.needs_perms.size ? action.needs_perms : [] %]
+                            [% needs_all = action.needs_all.size ? action.needs_all : [] %]
                             [% has_prefs_count = 0 %]
                             [% has_perms_count = 0 %]
+                            [% has_all_count = 0 %]
                             [% FOREACH pref IN needs_prefs %]
                                 [% IF Koha.Preference(pref) %]
                                     [% has_prefs_count = has_prefs_count + 1 %]
                                     [% has_perms_count = has_perms_count + 1 %]
                                 [% END %]
                             [% END %]
-                            [% NEXT IF has_prefs_count < needs_prefs.size || has_perms_count < needs_perms.size %]
+                            [% FOREACH func IN needs_all %]
+                                [% IF func(request) %]
+                                    [% has_all_count = has_all_count + 1 %]
+                                [% END %]
+                            [% END %]
+                            [% NEXT IF has_prefs_count < needs_prefs.size || has_perms_count < needs_perms.size || has_all_count < needs_all.size %]
                             [% IF action.method == 'migrate' %]
                                 [% IF backends.size > 2 %]
                                     <div class="dropdown btn-group">