Bug 23010: Add ability to block withdrawning of items with certain statuses

Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit b74dbf3d59)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Lucas Gass 2025-01-28 23:04:19 +00:00 committed by Paul Derscheid
parent db1bca48e6
commit 152af99174
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
3 changed files with 28 additions and 1 deletions

View File

@ -188,6 +188,24 @@ sub store {
}
}
my $prevent_withdrawing_of = C4::Context->preference('PreventWithDrawingItemsStatus');
my @statuses_to_prevent = defined $prevent_withdrawing_of ? split( ',', $prevent_withdrawing_of ) : ();
my $prevent_onloan = grep { $_ eq 'checkedout' } @statuses_to_prevent;
my $prevent_intransit = grep { $_ eq 'intransit' } @statuses_to_prevent;
if ( exists $updated_columns{withdrawn} && $updated_columns{withdrawn} ) {
my $transfer = $pre_mod_item->get_transfer;
if ( $pre_mod_item->onloan && $prevent_onloan ) {
Koha::Exceptions::Item::Transfer::OnLoan->throw( error => "onloan_cannot_withdraw" );
return $self->SUPER::store;
}
if ( defined $transfer && $transfer->in_transit && $prevent_intransit ) {
Koha::Exceptions::Item::Transfer::InTransit->throw( error => "intransit_cannot_withdraw" );
return $self->SUPER::store;
}
}
if ( exists $updated_columns{itemcallnumber}
or exists $updated_columns{cn_source} )
{

View File

@ -50,6 +50,7 @@ use MARC::File::XML;
use MIME::Base64 qw( decode_base64url encode_base64url );
use Storable qw( freeze thaw );
use URI::Escape qw( uri_escape_utf8 );
use Try::Tiny qw( catch try );
our $dbh = C4::Context->dbh;
@ -642,7 +643,13 @@ if ( $op eq "cud-additem" ) {
if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
LostItem( $item->itemnumber, 'additem' );
}
$item->store;
try {
$item->store;
} catch {
if ( ref $_ && $_->can('error') ) {
push @errors, $_->error;
}
}
}
$nextop = "cud-additem";

View File

@ -89,6 +89,8 @@
<h1>Items for [% biblio.title | html %] [% IF ( biblio.author ) %]by [% biblio.author | html %][% END %] (Record #[% biblio.biblionumber | html %])</h1>
<a id="newitem_jump" href="#f"><i class="fa fa-arrow-down"></i> Jump to form</a>
[% IF ( onloan_cannot_withdraw ) %]<div class="alert alert-warning"><strong>Error saving item</strong>: Onloan item cannot be withdrawn.</div>[% END %]
[% IF ( intransit_cannot_withdraw ) %]<div class="alert alert-warning"><strong>Error saving item</strong>: In transit item cannot be withdrawn.</div>[% END %]
[% IF ( barcode_not_unique ) %]<div class="alert alert-warning"><strong>Error saving item</strong>: Barcode must be unique.</div>[% END %]
[% IF ( no_next_barcode ) %]<div class="alert alert-warning"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div>[% END %]
[% IF ( book_on_loan ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item is checked out.</div>[% END %]