Bug 24860: Add ability to select an item group when placing a hold

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Rebecca Coert <rcoert@arlingtonva.us>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Kyle Hall 2022-06-03 06:33:25 -04:00 committed by Tomas Cohen Arazi
parent 9670e71b00
commit 8efe22b770
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
8 changed files with 129 additions and 4 deletions

View file

@ -162,6 +162,7 @@ BEGIN {
itemnumber => $itemnumber,
found => $found,
itemtype => $itemtype,
item_gorup_id => $item_group_id
}
);

View file

@ -525,6 +525,20 @@ sub item {
return $self->{_item};
}
=head3 item_group
Returns the related Koha::Biblio::ItemGroup object for this Hold
=cut
sub item_group {
my ($self) = @_;
my $item_group_rs = $self->_result->item_group;
return unless $item_group_rs;
return Koha::Biblio::ItemGroup->_new_from_dbic($item_group_rs);
}
=head3 branch
Returns the related Koha::Library object for this Hold

View file

@ -85,6 +85,9 @@ sub forced_hold_level {
my $item_level_count = $self->search( { itemnumber => { '!=' => undef } } )->count();
return 'item' if $item_level_count > 0;
my $item_group_level_count = $self->search( { item_group_id => { '!=' => undef } } )->count();
return 'item_group' if $item_group_level_count > 0;
my $record_level_count = $self->search( { itemnumber => undef } )->count();
return 'record' if $record_level_count > 0;

View file

@ -179,6 +179,8 @@
[%- ELSE -%]
[%- IF hold.itemtype -%]
<em>Next available [% ItemTypes.GetDescription( hold.itemtype ) | html %] item</em>
[%- ELSIF hold.object.item_group -%]
<em>Next available item from group <strong>[% hold.object.item_group.description | html %]</strong></em>
[%- ELSE -%]
<em>Next available</em>
[%- END -%]

View file

@ -599,7 +599,7 @@
[% UNLESS ( multi_hold ) %]
<li>
<label for="requestany">Hold next available item </label>
[% IF force_hold_level == 'item' %]
[% IF force_hold_level == 'item' || force_hold_level == 'item_group' %]
<input type="checkbox" id="requestany" name="request" disabled="true" />
[% ELSIF force_hold_level == 'record' %]
<input type="checkbox" id="requestany" checked="checked" value="Any" disabled="true"/>
@ -658,6 +658,52 @@
[% END %]
</ol>
<!-- ItemGroup level holds -->
[% IF Koha.Preference('EnableItemGroupHolds') && biblio.object.item_groups.count %]
<h2 style="padding: 0 1em;">
Hold next available item from an item group
[% IF force_hold_level == 'item_group' %]
<span class="error"><i>(Required)</i></span>
[% END %]
</h2>
[% IF force_hold_level == 'record' # Patron has placed a record level hold previously for this record %]
<span class="error">
<i class="fa fa-times fa-lg" title="Cannot be put on hold"></i>
Hold must be record level
</span>
[% ELSIF force_hold_level == 'item' # Patron has placed an item level hold previously for this record %]
<span class="error">
<i class="fa fa-times fa-lg" title="Cannot be put on hold"></i>
Hold must be item level
</span>
[% ELSE %]
<table>
<thead>
<tr>
<th>Hold</th>
<th>Item group</th>
</tr>
</thead>
<tbody>
[% FOREACH g IN biblio.object.item_groups.search({}, { order_by => ['display_order'] }) %]
[% IF g.items %]
<tr>
<td>
<input id="item_group_id_[% g.id | html %]" type="radio" name="item_group_id" value="[% g.id | html %]" />
</td>
<td>
<label for="item_group_id_[% g.id | html %]">[% g.description | html %]</label>
</td>
</tr>
[% END %]
[% END %]
</tbody>
</table>
[% END %]
[% END %]
<!-- /ItemGroup level holds -->
<h2 style="padding: 0 1em;">
Place a hold on a specific item
[% IF force_hold_level == 'item' %]
@ -674,6 +720,9 @@
<th>Item type</th>
[% END %]
<th>Barcode</th>
[% IF Koha.Preference('EnableItemGroupHolds') && biblio.object.item_groups.count %]
<th>Item group</th>
[% END %]
<th>Home library</th>
<th>Last location</th>
[% IF itemdata_ccode %]
@ -698,6 +747,11 @@
<i class="fa fa-times fa-lg" title="Cannot be put on hold"></i>
Hold must be record level
</span>
[% ELSIF force_hold_level == 'item_group' %]
<span class="error">
<i class="fa fa-times fa-lg" title="Cannot be put on hold"></i>
Hold must be item group level
</span>
[% ELSIF ( itemloo.available ) %]
<input type="radio" name="checkitem" value="[% itemloo.itemnumber | html %]" />
[% ELSIF ( itemloo.override ) %]
@ -767,6 +821,11 @@
<td>
[% itemloo.barcode | html %]
</td>
[% IF Koha.Preference('EnableItemGroupHolds') && biblio.object.item_groups.count %]
<td>
[% itemloo.object.item_group.description | html %]
</td>
[% END %]
<td>
[% Branches.GetName( itemloo.homebranch ) | html %]
</td>
@ -1346,6 +1405,8 @@
};
if($('input[name="checkitem"]:checked').length)
data.item_id = $('input[name="checkitem"]:checked').val();
if($('input[name="item_group_id"]:checked').length)
data.item_group_id = $('input[name="item_group_id"]:checked').val();
if($('input[name="borrowernumber"]').length)
data.patron_id = $('input[name="borrowernumber"]').val();
if($('textarea[name="notes"]').length)
@ -1391,8 +1452,8 @@
});
[% UNLESS ( multi_hold ) %]
$("#hold-request-form").on("submit", function(){
return check($(this));
$("#hold-request-form").on("submit", function(e){
return check(e, $(this));
});
[% ELSE %]
$("#hold-request-form").on("submit", function(){
@ -1436,7 +1497,7 @@
});
});
function check( table ) {
function check( e, table ) {
var msg = "";
@ -1467,6 +1528,7 @@
$('#hold-request-form').preventDoubleFormSubmit();
return(true);
} else {
e.preventDefault();
alert(msg);
return(false);
}
@ -1620,6 +1682,16 @@
stickyClass: "floating"
});
[% IF Koha.Preference('EnableItemGroupHolds') %]
$(':radio[name="item_group_id"]').change(function(){
$(':radio[name="checkitem"]').prop('checked', false);
});
$(':radio[name="checkitem"]').change(function(){
$(':radio[name="item_group_id"]').prop('checked', false);
});
[% END %]
if(!localStorage.selectedHolds || document.referrer.replace(/\?.*/, '') !== document.location.origin+document.location.pathname) {
localStorage.selectedHolds = [];
}

View file

@ -45,6 +45,7 @@ my $startdate = $input->param('reserve_date') || '';
my @rank = $input->multi_param('rank-request');
my $title = $input->param('title');
my $checkitem = $input->param('checkitem');
my $item_group_id = $input->param('item_group_id');
my $expirationdate = $input->param('expiration_date');
my $itemtype = $input->param('itemtype') || undef;
my $non_priority = $input->param('non_priority');
@ -140,6 +141,7 @@ if ( $patron ) {
found => $found,
itemtype => $itemtype,
non_priority => $non_priority,
item_group_id => $item_group_id,
}
);
}

View file

@ -299,12 +299,15 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold )
my %biblioloopiter = ();
my $biblio = Koha::Biblios->find( $biblionumber );
unless ($biblio) {
$biblioloopiter{noitems} = 1;
$template->param('nobiblio' => 1);
last;
}
$biblioloopiter{object} = $biblio;
if ( $patron ) {
{ # CanBookBeReserved
my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
@ -397,6 +400,7 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold )
for my $item_object ( @items ) {
my $do_check;
my $item = $item_object->unblessed;
$item->{object} = $item_object;
if ( $patron ) {
$do_check = $patron->do_check_for_previous_checkout($item) if $wants_check;
if ( $do_check && $wants_check ) {

View file

@ -25,6 +25,7 @@ use Test::Warn;
use C4::Circulation qw( AddIssue );
use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll );
use Koha::AuthorisedValueCategory;
use Koha::Biblio::ItemGroups;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string );
use Koha::Holds;
@ -641,6 +642,32 @@ subtest 'set_waiting+patron_expiration_date' => sub {
};
};
subtest 'Test Koha::Hold::item_group' => sub {
plan tests => 1;
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $item = $builder->build_sample_item;
my $item_group = $builder->build_object(
{
class => 'Koha::Biblio::ItemGroups',
value => { biblionumber => $item->biblionumber }
}
);
my $reserve_id = AddReserve(
{
branchcode => $library->branchcode,
borrowernumber => $patron->borrowernumber,
biblionumber => $item->biblionumber,
itemnumber => $item->itemnumber,
item_group_id => $item_group->id,
}
);
my $hold = Koha::Holds->find($reserve_id);
is( $hold->item_group_id, $item_group->id,
'Koha::Hold::item_group returns the correct item_group' );
};
$schema->storage->txn_rollback;