Bug 30708: Do not allow copy item to a train if the item already exists in a non-received train
Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: BULAC - http://www.bulac.fr/ Signed-off-by: Heather Hernandez <heather_hernandez@nps.gov> Signed-off-by: Laurence Rault <laurence.rault@biblibre.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
2c61a7af95
commit
3970889e71
|
|
@ -33,6 +33,11 @@ use Exception::Class (
|
|||
isa => 'Koha::Exceptions::Preservation',
|
||||
description => "Cannot add item to waiting list, it is already in a non-received train",
|
||||
},
|
||||
'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain' => {
|
||||
isa => 'Koha::Exceptions::Preservation',
|
||||
description => "Cannot add item to this train, it is already in an other non-received train",
|
||||
fields => ['train_id'],
|
||||
},
|
||||
'Koha::Exceptions::Preservation::ItemNotInWaitingList' => {
|
||||
isa => 'Koha::Exceptions::Preservation',
|
||||
description => "Cannot add item to train, it is not in the waiting list",
|
||||
|
|
|
|||
|
|
@ -77,6 +77,17 @@ sub add_item {
|
|||
Koha::Exceptions::Preservation::ItemNotInWaitingList->throw
|
||||
if !$skip_waiting_list_check && $item->notforloan != $not_for_loan;
|
||||
|
||||
my $already_in_train = Koha::Preservation::Train::Items->search(
|
||||
{ item_id => $train_item->{item_id}, 'train.received_on' => undef },
|
||||
{
|
||||
join => 'train'
|
||||
}
|
||||
);
|
||||
if ( $already_in_train->count ) {
|
||||
my $train_id = $already_in_train->next->train_id;
|
||||
Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain->throw( train_id => $train_id );
|
||||
}
|
||||
|
||||
# FIXME We need a LOCK here
|
||||
# Not important for now as we have add_items
|
||||
# Note that there are several other places in Koha with this max+1 problem
|
||||
|
|
|
|||
|
|
@ -382,7 +382,13 @@ sub add_item {
|
|||
status => 400,
|
||||
openapi => { error => 'Item not in waiting list' }
|
||||
);
|
||||
} elsif ( $_->isa('Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain') ) {
|
||||
return $c->render(
|
||||
status => 409,
|
||||
openapi => { error => 'Item already in a non-received train', train_id => $_->train_id }
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$c->unhandled_exception($_);
|
||||
|
|
@ -474,6 +480,11 @@ sub copy_item {
|
|||
status => 400,
|
||||
openapi => { error => 'Item not in waiting list' }
|
||||
);
|
||||
} elsif ( $_->isa('Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain') ) {
|
||||
return $c->render(
|
||||
status => 409,
|
||||
openapi => { error => 'Item already in a non-received train', train_id => $_->train_id }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -197,7 +197,8 @@ export default {
|
|||
const AVStore = inject("AVStore")
|
||||
const { get_lib_from_av } = AVStore
|
||||
|
||||
const { setConfirmationDialog, setMessage } = inject("mainStore")
|
||||
const { setConfirmationDialog, setMessage, setWarning } =
|
||||
inject("mainStore")
|
||||
|
||||
const table_id = "item_list"
|
||||
useDataTable(table_id)
|
||||
|
|
@ -208,6 +209,7 @@ export default {
|
|||
table_id,
|
||||
setConfirmationDialog,
|
||||
setMessage,
|
||||
setWarning,
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
|
@ -421,7 +423,13 @@ export default {
|
|||
this.setMessage(this.$__("Item copied successfully."))
|
||||
this.show_modal = false
|
||||
},
|
||||
error => {}
|
||||
error => {
|
||||
this.setWarning(
|
||||
this.$__(
|
||||
"Item cannot be copied to a train, it is already in a non-received train."
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
build_datatable: function () {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use Test::Warn;
|
|||
|
||||
use Koha::Preservation::Trains;
|
||||
use Koha::Database;
|
||||
use Koha::DateUtils qw( dt_from_string );
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
use t::lib::Mocks;
|
||||
|
|
@ -52,7 +53,7 @@ subtest 'default_processing' => sub {
|
|||
};
|
||||
|
||||
subtest 'add_items & items' => sub {
|
||||
plan tests => 12;
|
||||
plan tests => 13;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
|
@ -104,5 +105,23 @@ subtest 'add_items & items' => sub {
|
|||
is( $train->items->count, 3, 'the item has been added to the train' );
|
||||
is( $item_2->get_from_storage->notforloan, $not_for_loan_train_in );
|
||||
|
||||
my $another_train = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Preservation::Trains',
|
||||
value => {
|
||||
not_for_loan => $not_for_loan_train_in,
|
||||
closed_on => undef,
|
||||
sent_on => undef,
|
||||
received_on => undef
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$train->closed_on(dt_from_string)->store;
|
||||
|
||||
throws_ok {
|
||||
$another_train->add_item( { item_id => $item_1->itemnumber }, { skip_waiting_list_check => 1 });
|
||||
} 'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain';
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue