View | Details | Raw Unified | Return to bug 30708
Collapse All | Expand All

(-)a/Koha/Exceptions/Preservation.pm (+5 lines)
Lines 33-38 use Exception::Class ( Link Here
33
        isa         => 'Koha::Exceptions::Preservation',
33
        isa         => 'Koha::Exceptions::Preservation',
34
        description => "Cannot add item to waiting list, it is already in a non-received train",
34
        description => "Cannot add item to waiting list, it is already in a non-received train",
35
    },
35
    },
36
    'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain' => {
37
        isa         => 'Koha::Exceptions::Preservation',
38
        description => "Cannot add item to this train, it is already in an other non-received train",
39
        fields      => ['train_id'],
40
    },
36
    'Koha::Exceptions::Preservation::ItemNotInWaitingList' => {
41
    'Koha::Exceptions::Preservation::ItemNotInWaitingList' => {
37
        isa         => 'Koha::Exceptions::Preservation',
42
        isa         => 'Koha::Exceptions::Preservation',
38
        description => "Cannot add item to train, it is not in the waiting list",
43
        description => "Cannot add item to train, it is not in the waiting list",
(-)a/Koha/Preservation/Train.pm (+11 lines)
Lines 77-82 sub add_item { Link Here
77
    Koha::Exceptions::Preservation::ItemNotInWaitingList->throw
77
    Koha::Exceptions::Preservation::ItemNotInWaitingList->throw
78
      if !$skip_waiting_list_check && $item->notforloan != $not_for_loan;
78
      if !$skip_waiting_list_check && $item->notforloan != $not_for_loan;
79
79
80
    my $already_in_train = Koha::Preservation::Train::Items->search(
81
        { item_id => $train_item->{item_id}, 'train.received_on' => undef },
82
        {
83
            join => 'train'
84
        }
85
    );
86
    if ( $already_in_train->count ) {
87
        my $train_id = $already_in_train->next->train_id;
88
        Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain->throw( train_id => $train_id );
89
    }
90
80
    # FIXME We need a LOCK here
91
    # FIXME We need a LOCK here
81
    # Not important for now as we have add_items
92
    # Not important for now as we have add_items
82
    # Note that there are several other places in Koha with this max+1 problem
93
    # Note that there are several other places in Koha with this max+1 problem
(-)a/Koha/REST/V1/Preservation/Trains.pm (+11 lines)
Lines 382-388 sub add_item { Link Here
382
                    status  => 400,
382
                    status  => 400,
383
                    openapi => { error => 'Item not in waiting list' }
383
                    openapi => { error => 'Item not in waiting list' }
384
                );
384
                );
385
            } elsif ( $_->isa('Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain') ) {
386
                return $c->render(
387
                    status  => 409,
388
                    openapi => { error => 'Item already in a non-received train', train_id => $_->train_id }
389
                );
385
            }
390
            }
391
386
        }
392
        }
387
393
388
        $c->unhandled_exception($_);
394
        $c->unhandled_exception($_);
Lines 474-479 sub copy_item { Link Here
474
                    status  => 400,
480
                    status  => 400,
475
                    openapi => { error => 'Item not in waiting list' }
481
                    openapi => { error => 'Item not in waiting list' }
476
                );
482
                );
483
            } elsif ( $_->isa('Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain') ) {
484
                return $c->render(
485
                    status  => 409,
486
                    openapi => { error => 'Item already in a non-received train', train_id => $_->train_id }
487
                );
477
            }
488
            }
478
        }
489
        }
479
490
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue (-2 / +10 lines)
Lines 198-204 export default { Link Here
198
        const AVStore = inject("AVStore")
198
        const AVStore = inject("AVStore")
199
        const { get_lib_from_av } = AVStore
199
        const { get_lib_from_av } = AVStore
200
200
201
        const { setConfirmationDialog, setMessage } = inject("mainStore")
201
        const { setConfirmationDialog, setMessage, setWarning } =
202
            inject("mainStore")
202
203
203
        const table_id = "item_list"
204
        const table_id = "item_list"
204
        useDataTable(table_id)
205
        useDataTable(table_id)
Lines 209-214 export default { Link Here
209
            table_id,
210
            table_id,
210
            setConfirmationDialog,
211
            setConfirmationDialog,
211
            setMessage,
212
            setMessage,
213
            setWarning,
212
        }
214
        }
213
    },
215
    },
214
    data() {
216
    data() {
Lines 422-428 export default { Link Here
422
                        this.setMessage(this.$__("Item copied successfully."))
424
                        this.setMessage(this.$__("Item copied successfully."))
423
                        this.show_modal = false
425
                        this.show_modal = false
424
                    },
426
                    },
425
                    error => {}
427
                    error => {
428
                        this.setWarning(
429
                            this.$__(
430
                                "Item cannot be copied to a train, it is already in a non-received train."
431
                            )
432
                        )
433
                    }
426
                )
434
                )
427
        },
435
        },
428
        build_datatable: function () {
436
        build_datatable: function () {
(-)a/t/db_dependent/Koha/Preservation/Trains.t (-2 / +20 lines)
Lines 23-28 use Test::Warn; Link Here
23
23
24
use Koha::Preservation::Trains;
24
use Koha::Preservation::Trains;
25
use Koha::Database;
25
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
26
27
27
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
28
use t::lib::Mocks;
29
use t::lib::Mocks;
Lines 52-58 subtest 'default_processing' => sub { Link Here
52
};
53
};
53
54
54
subtest 'add_items & items' => sub {
55
subtest 'add_items & items' => sub {
55
    plan tests => 12;
56
    plan tests => 13;
56
57
57
    $schema->storage->txn_begin;
58
    $schema->storage->txn_begin;
58
59
Lines 104-108 subtest 'add_items & items' => sub { Link Here
104
    is( $train->items->count, 3, 'the item has been added to the train' );
105
    is( $train->items->count, 3, 'the item has been added to the train' );
105
    is( $item_2->get_from_storage->notforloan, $not_for_loan_train_in );
106
    is( $item_2->get_from_storage->notforloan, $not_for_loan_train_in );
106
107
108
    my $another_train = $builder->build_object(
109
        {
110
            class => 'Koha::Preservation::Trains',
111
            value => {
112
                not_for_loan => $not_for_loan_train_in,
113
                closed_on    => undef,
114
                sent_on      => undef,
115
                received_on  => undef
116
            }
117
        }
118
    );
119
120
    $train->closed_on(dt_from_string)->store;
121
122
    throws_ok {
123
        $another_train->add_item( { item_id => $item_1->itemnumber }, { skip_waiting_list_check => 1 });
124
    } 'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain';
125
107
    $schema->storage->txn_rollback;
126
    $schema->storage->txn_rollback;
108
};
127
};
109
- 

Return to bug 30708