From 527192765d6673754844fa08fdc0b7da3235bb75 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Thu, 5 Mar 2020 09:27:32 +0000 Subject: [PATCH] Bug 23112: (follow-up) Conditionally prevent checkout 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. https://bugs.koha-community.org/show_bug.cgi?id=23112 --- Koha/Illrequest.pm | 26 +++++++++++++++++++--- .../prog/en/modules/ill/ill-requests.tt | 9 +++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index c6280d2057..a11ff8601f 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -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' }, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt index 413e4a190a..b5ccab44b8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt @@ -441,8 +441,10 @@ [% 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 %] @@ -454,7 +456,12 @@ [% 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 %]