diff --git a/Koha/Item.pm b/Koha/Item.pm index 87e6dd8c31..35d52c1d0d 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -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} ) { diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index fecd4fa6a8..6c8a5bef1e 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -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; @@ -641,7 +642,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"; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 81edf34130..7b55c3c666 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -88,6 +88,8 @@