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

(-)a/Koha/Exceptions/Preservation.pm (+5 lines)
Lines 46-51 use Exception::Class ( Link Here
46
        isa         => 'Koha::Exceptions::Preservation',
46
        isa         => 'Koha::Exceptions::Preservation',
47
        description => "Cannot add item to train, the item does not exist",
47
        description => "Cannot add item to train, the item does not exist",
48
    },
48
    },
49
    'Koha::Exceptions::Preservation::CannotAddItemToClosedTrain' => {
50
        isa         => 'Koha::Exceptions::Preservation',
51
        description => "Cannot add item to a closed train",
52
    },
53
49
);
54
);
50
55
51
sub full_message {
56
sub full_message {
(-)a/Koha/Preservation/Train.pm (+2 lines)
Lines 66-71 skip_waitin_list_check can be set to true if the item can be added to the train Link Here
66
sub add_item {
66
sub add_item {
67
    my ( $self, $train_item, $params ) = @_;
67
    my ( $self, $train_item, $params ) = @_;
68
68
69
    Koha::Exceptions::Preservation::CannotAddItemToClosedTrain->throw if $self->closed_on;
70
69
    my $skip_waiting_list_check = $params->{skip_waiting_list_check} || 0;
71
    my $skip_waiting_list_check = $params->{skip_waiting_list_check} || 0;
70
72
71
    my $not_for_loan = C4::Context->preference('PreservationNotForLoanWaitingListIn');
73
    my $not_for_loan = C4::Context->preference('PreservationNotForLoanWaitingListIn');
(-)a/Koha/REST/V1/Preservation/Trains.pm (-2 / +13 lines)
Lines 332-338 sub add_items { Link Here
332
332
333
=head3 add_item
333
=head3 add_item
334
334
335
Controller function that handles adding items in batch to a train
335
Controller function that handles adding a new item to a train
336
336
337
=cut
337
=cut
338
338
Lines 387-394 sub add_item { Link Here
387
                    status  => 409,
387
                    status  => 409,
388
                    openapi => { error => 'Item already in a non-received train', train_id => $_->train_id }
388
                    openapi => { error => 'Item already in a non-received train', train_id => $_->train_id }
389
                );
389
                );
390
            } elsif ( $_->isa('Koha::Exceptions::Preservation::CannotAddItemToClosedTrain') ) {
391
                return $c->render(
392
                    status  => 400,
393
                    openapi => { error => 'Cannot add item to a closed train' }
394
                );
390
            }
395
            }
391
392
        }
396
        }
393
397
394
        $c->unhandled_exception($_);
398
        $c->unhandled_exception($_);
Lines 397-402 sub add_item { Link Here
397
401
398
=head3 copy_item
402
=head3 copy_item
399
403
404
Controller function that handles copying an item from a train to an other
405
400
=cut
406
=cut
401
407
402
sub copy_item {
408
sub copy_item {
Lines 485-490 sub copy_item { Link Here
485
                    status  => 409,
491
                    status  => 409,
486
                    openapi => { error => 'Item already in a non-received train', train_id => $_->train_id }
492
                    openapi => { error => 'Item already in a non-received train', train_id => $_->train_id }
487
                );
493
                );
494
            } elsif ( $_->isa('Koha::Exceptions::Preservation::CannotAddItemToClosedTrain') ) {
495
                return $c->render(
496
                    status  => 400,
497
                    openapi => { error => 'Cannot add item to a closed train' }
498
                );
488
            }
499
            }
489
        }
500
        }
490
501
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsList.vue (-6 / +12 lines)
Lines 64-70 export default { Link Here
64
    setup() {
64
    setup() {
65
        const AVStore = inject("AVStore")
65
        const AVStore = inject("AVStore")
66
        const { get_lib_from_av, map_av_dt_filter } = AVStore
66
        const { get_lib_from_av, map_av_dt_filter } = AVStore
67
        const { setConfirmationDialog, setMessage } = inject("mainStore")
67
        const { setConfirmationDialog, setMessage, setWarning } =
68
            inject("mainStore")
68
        const table = ref()
69
        const table = ref()
69
        const filters = reactive({ status: "" })
70
        const filters = reactive({ status: "" })
70
        return {
71
        return {
Lines 72-77 export default { Link Here
72
            map_av_dt_filter,
73
            map_av_dt_filter,
73
            setConfirmationDialog,
74
            setConfirmationDialog,
74
            setMessage,
75
            setMessage,
76
            setWarning,
75
            table,
77
            table,
76
            filters,
78
            filters,
77
        }
79
        }
Lines 156-166 export default { Link Here
156
            )
158
            )
157
        },
159
        },
158
        doAddItems: function (train, dt, event) {
160
        doAddItems: function (train, dt, event) {
159
            this.$router.push(
161
            if (train.closed_on != null) {
160
                "/cgi-bin/koha/preservation/trains/" +
162
                this.setWarning(this.$__("Cannot add items to a closed train"))
161
                    train.train_id +
163
            } else {
162
                    "/items/add"
164
                this.$router.push(
163
            )
165
                    "/cgi-bin/koha/preservation/trains/" +
166
                        train.train_id +
167
                        "/items/add"
168
                )
169
            }
164
        },
170
        },
165
        table_url() {
171
        table_url() {
166
            let url = "/api/v1/preservation/trains"
172
            let url = "/api/v1/preservation/trains"
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue (+9 lines)
Lines 49-59 Link Here
49
    <div v-else id="trains_show">
49
    <div v-else id="trains_show">
50
        <div id="toolbar" class="btn-toolbar">
50
        <div id="toolbar" class="btn-toolbar">
51
            <router-link
51
            <router-link
52
                v-if="train.closed_on == null"
52
                :to="`/cgi-bin/koha/preservation/trains/${train.train_id}/items/add`"
53
                :to="`/cgi-bin/koha/preservation/trains/${train.train_id}/items/add`"
53
                class="btn btn-default"
54
                class="btn btn-default"
54
                ><font-awesome-icon icon="plus" />
55
                ><font-awesome-icon icon="plus" />
55
                {{ $__("Add items") }}</router-link
56
                {{ $__("Add items") }}</router-link
56
            >
57
            >
58
            <span
59
                v-else
60
                class="btn btn-default"
61
                disabled="disabled"
62
                :title="$__('Cannot add items to a closed train')"
63
            >
64
                <font-awesome-icon icon="plus" /> {{ $__("Add items") }}
65
            </span>
57
            <router-link
66
            <router-link
58
                :to="`/cgi-bin/koha/preservation/trains/edit/${train.train_id}`"
67
                :to="`/cgi-bin/koha/preservation/trains/edit/${train.train_id}`"
59
                class="btn btn-default"
68
                class="btn btn-default"
(-)a/t/db_dependent/Koha/Preservation/Trains.t (-3 / +7 lines)
Lines 53-59 subtest 'default_processing' => sub { Link Here
53
};
53
};
54
54
55
subtest 'add_items & items' => sub {
55
subtest 'add_items & items' => sub {
56
    plan tests => 13;
56
    plan tests => 14;
57
57
58
    $schema->storage->txn_begin;
58
    $schema->storage->txn_begin;
59
59
Lines 120-127 subtest 'add_items & items' => sub { Link Here
120
    $train->closed_on(dt_from_string)->store;
120
    $train->closed_on(dt_from_string)->store;
121
121
122
    throws_ok {
122
    throws_ok {
123
        $another_train->add_item( { item_id => $item_1->itemnumber }, { skip_waiting_list_check => 1 });
123
        $another_train->add_item( { item_id => $item_1->itemnumber }, { skip_waiting_list_check => 1 } );
124
    } 'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain';
124
    } 'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain';
125
125
126
    my $item_4 = $builder->build_sample_item;
127
    throws_ok {
128
        $train->add_item( { item_id => $item_4->itemnumber } );
129
    } 'Koha::Exceptions::Preservation::CannotAddItemToClosedTrain';
130
126
    $schema->storage->txn_rollback;
131
    $schema->storage->txn_rollback;
127
};
132
};
128
- 

Return to bug 30708