From 5c5abb03d60b00c1565968966c3e9903e791a5e8 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Tue, 28 Jan 2025 23:04:19 +0000 Subject: [PATCH] Bug 23010: Add ability to block withdrawning of items with certain statuses --- Koha/Item.pm | 18 ++++++++++++++++++ cataloguing/additem.pl | 10 +++++++++- .../prog/en/modules/cataloguing/additem.tt | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 07fc6ad5c8c..bbef037248c 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -187,6 +187,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 3d361ec1e63..dc83c51a45b 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; @@ -644,7 +645,14 @@ 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 a41569fe99e..2f9014c2db5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -74,7 +74,6 @@ [% END %] [% END #/ WRAPPER breadcrumbs %] [% END #/ WRAPPER sub-header.inc %] -
@@ -88,6 +87,8 @@

Items for [% biblio.title | html %] [% IF ( biblio.author ) %] by [% biblio.author | html %][% END %] (Record #[% biblio.biblionumber | html %])

Jump to add item form +[% IF ( onloan_cannot_withdraw ) %]
Error saving item: Onloan item cannot be withdrawn.
[% END %] +[% IF ( intransit_cannot_withdraw ) %]
Error saving item: In transit item cannot be withdrawn.
[% END %] [% IF ( barcode_not_unique ) %]
Error saving item: Barcode must be unique.
[% END %] [% IF ( no_next_barcode ) %]
Error saving items: Unable to automatically determine values for barcodes. No item has been inserted.
[% END %] [% IF ( book_on_loan ) %]
Cannot delete: item is checked out.
[% END %] -- 2.39.5