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

(-)a/Koha/Exceptions/Item/Bundle.pm (+4 lines)
Lines 31-36 use Exception::Class ( Link Here
31
        isa         => 'Koha::Exceptions::Item::Bundle',
31
        isa         => 'Koha::Exceptions::Item::Bundle',
32
        description => 'Someone tried to add a checked out item to a bundle',
32
        description => 'Someone tried to add a checked out item to a bundle',
33
    },
33
    },
34
    'Koha::Exceptions::Item::Bundle::ItemIsLost' => {
35
        isa         => 'Koha::Exceptions::Item::Bundle',
36
        description => 'Someone tried to add a lost item to a bundle',
37
    },
34
);
38
);
35
39
36
=head1 NAME
40
=head1 NAME
(-)a/Koha/Item.pm (+8 lines)
Lines 1734-1739 sub add_to_bundle { Link Here
1734
                    }
1734
                    }
1735
                }
1735
                }
1736
1736
1737
                if ($bundle_item->itemlost > 0) {
1738
                    unless ($options->{mark_lost_item_as_found}) {
1739
                        Koha::Exceptions::Item::Bundle::ItemIsLost->throw();
1740
                    }
1741
1742
                    $bundle_item->itemlost(0);
1743
                }
1744
1737
                $self->_result->add_to_item_bundles_hosts(
1745
                $self->_result->add_to_item_bundles_hosts(
1738
                    { item => $bundle_item->itemnumber } );
1746
                    { item => $bundle_item->itemnumber } );
1739
1747
(-)a/Koha/REST/V1/Items.pm (-2 / +16 lines)
Lines 277-284 sub add_to_bundle { Link Here
277
    }
277
    }
278
278
279
    return try {
279
    return try {
280
        my $force_checkin = $c->validation->param('body')->{'force_checkin'};
280
        my $body = $c->validation->param('body');
281
        my $link = $item->add_to_bundle($bundle_item, { force_checkin => $force_checkin });
281
        my $options = {
282
            force_checkin => $body->{force_checkin},
283
            mark_lost_item_as_found => $body->{mark_lost_item_as_found},
284
        };
285
286
        my $link = $item->add_to_bundle($bundle_item, $options);
282
        return $c->render(
287
        return $c->render(
283
            status  => 201,
288
            status  => 201,
284
            openapi => $bundle_item
289
            openapi => $bundle_item
Lines 314-319 sub add_to_bundle { Link Here
314
                }
319
                }
315
            );
320
            );
316
        }
321
        }
322
        elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::ItemIsLost' ) {
323
            return $c->render(
324
                status  => 409,
325
                openapi => {
326
                    error      => 'Item is lost',
327
                    error_code => 'lost'
328
                }
329
            );
330
        }
317
        elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) {
331
        elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) {
318
            return $c->render(
332
            return $c->render(
319
                status  => 400,
333
                status  => 400,
(-)a/api/v1/swagger/definitions/bundle_link.yaml (+4 lines)
Lines 15-18 properties: Link Here
15
    type:
15
    type:
16
      - boolean
16
      - boolean
17
      - "null"
17
      - "null"
18
  mark_lost_item_as_found:
19
    type:
20
      - boolean
21
      - "null"
18
additionalProperties: false
22
additionalProperties: false
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (+12 lines)
Lines 1803-1808 Note that permanent location is a code, and location may be an authval. Link Here
1803
                                .empty()
1803
                                .empty()
1804
                                .attr('class', 'alert alert-danger')
1804
                                .attr('class', 'alert alert-danger')
1805
                                .append(__x('Failure: Item {barcode} cannot be checked in', { barcode }))
1805
                                .append(__x('Failure: Item {barcode} cannot be checked in', { barcode }))
1806
                          } else if (response.error_code === 'lost') {
1807
                              const button = $('<button type="button">')
1808
                                .addClass('btn btn-xs')
1809
                                .text(__('Mark as found and add to bundle'))
1810
                                .on('click', function () {
1811
                                    addToBundle(url, { external_id: barcode, mark_lost_item_as_found: true });
1812
                                });
1813
                              $('#addResult')
1814
                                .empty()
1815
                                .attr('class', 'alert alert-warning')
1816
                                .append(__x('Warning: Item {barcode} is marked as lost', { barcode }))
1817
                                .append(' ', button);
1806
                          } else {
1818
                          } else {
1807
                              $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' belongs to another bundle").format(barcode)+'</div>');
1819
                              $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' belongs to another bundle").format(barcode)+'</div>');
1808
                          }
1820
                          }
(-)a/t/db_dependent/Koha/Item.t (-2 / +13 lines)
Lines 213-219 subtest 'bundle_host tests' => sub { Link Here
213
};
213
};
214
214
215
subtest 'add_to_bundle tests' => sub {
215
subtest 'add_to_bundle tests' => sub {
216
    plan tests => 7;
216
    plan tests => 13;
217
217
218
    $schema->storage->txn_begin;
218
    $schema->storage->txn_begin;
219
219
Lines 227-232 subtest 'add_to_bundle tests' => sub { Link Here
227
    my $host_item = $builder->build_sample_item();
227
    my $host_item = $builder->build_sample_item();
228
    my $bundle_item1 = $builder->build_sample_item();
228
    my $bundle_item1 = $builder->build_sample_item();
229
    my $bundle_item2 = $builder->build_sample_item();
229
    my $bundle_item2 = $builder->build_sample_item();
230
    my $bundle_item3 = $builder->build_sample_item();
230
231
231
    throws_ok { $host_item->add_to_bundle($host_item) }
232
    throws_ok { $host_item->add_to_bundle($host_item) }
232
    'Koha::Exceptions::Item::Bundle::IsBundle',
233
    'Koha::Exceptions::Item::Bundle::IsBundle',
Lines 267-272 subtest 'add_to_bundle tests' => sub { Link Here
267
    $bundle_item2->discard_changes;
268
    $bundle_item2->discard_changes;
268
    ok( !$bundle_item2->checkout, 'Item is not checked out after being added to a bundle' );
269
    ok( !$bundle_item2->checkout, 'Item is not checked out after being added to a bundle' );
269
270
271
    $bundle_item3->itemlost(1)->store;
272
    throws_ok { $host_item->add_to_bundle($bundle_item3) }
273
    'Koha::Exceptions::Item::Bundle::ItemIsLost',
274
      'Exception thrown if you try to add a lost item to a bundle';
275
276
    lives_ok { $host_item->add_to_bundle($bundle_item3, { mark_lost_item_as_found => 1 }) }
277
      'No exception thrown if you try to add a lost item to a bundle using "mark_lost_item_as_found"';
278
279
    $bundle_item3->discard_changes;
280
    is($bundle_item3->itemlost, 0, 'Item is marked as found after being added to a bundle');
281
270
    $schema->storage->txn_rollback;
282
    $schema->storage->txn_rollback;
271
};
283
};
272
284
273
- 

Return to bug 33025