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

(-)a/Koha/Biblio/Volume.pm (-1 / +1 lines)
Lines 68-74 sub items { Link Here
68
    my $items_rs = $self->_result->volume_items;
68
    my $items_rs = $self->_result->volume_items;
69
    my @item_numbers = $items_rs->get_column('itemnumber')->all;
69
    my @item_numbers = $items_rs->get_column('itemnumber')->all;
70
70
71
    return unless @item_numbers;
71
    return Koha::Items->new->empty unless @item_numbers;
72
72
73
    return Koha::Items->search(
73
    return Koha::Items->search(
74
        {
74
        {
(-)a/Koha/Item.pm (-13 / +8 lines)
Lines 223-246 sub delete { Link Here
223
    # FIXME check the item has no current issues
223
    # FIXME check the item has no current issues
224
    # i.e. raise the appropriate exception
224
    # i.e. raise the appropriate exception
225
225
226
    # Get the volume so we can delete it later if it has no items left
227
    my $volume = C4::Context->preference('EnableVolumes') ? $self->volume : undef;
228
226
    my $result = $self->SUPER::delete;
229
    my $result = $self->SUPER::delete;
227
230
231
    # Delete the volume if it has no items left
232
    $volume->delete if ( $volume && $volume->items->count == 0 );
233
228
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
234
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
229
    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
235
    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
230
        unless $params->{skip_record_index};
236
        unless $params->{skip_record_index};
231
237
232
    if ( C4::Context->preference('EnableVolumes') ) {
233
        my $volume_item =
234
          Koha::Biblio::Volume::Items->find( { itemnumber => $self->itemnumber } );
235
        my $volume_id = $volume_item ? $volume_item->volume_id : undef;
236
237
        # If this item is the last item on a volume, delete the volume as well
238
        if ($volume_id) {
239
            my $volume = Koha::Biblio::Volumes->find($volume_id);
240
            $volume->delete unless $volume->items->count > 1;
241
        }
242
    }
243
244
    $self->_after_item_action_hooks({ action => 'delete' });
238
    $self->_after_item_action_hooks({ action => 'delete' });
245
239
246
    logaction( "CATALOGUING", "DELETE", $self->itemnumber, "item" )
240
    logaction( "CATALOGUING", "DELETE", $self->itemnumber, "item" )
Lines 423-429 sub volume { Link Here
423
    my $volume_rs = $volume_item->volume;
417
    my $volume_rs = $volume_item->volume;
424
    return unless $volume_rs;
418
    return unless $volume_rs;
425
419
426
    return Koha::Biblio::Volume->_new_from_dbic( $volume_rs );
420
    my $volume = Koha::Biblio::Volume->_new_from_dbic( $volume_rs );
421
    return $volume;
427
}
422
}
428
423
429
=head3 holds
424
=head3 holds
(-)a/t/db_dependent/Koha/Volumes.t (-5 / +9 lines)
Lines 73-83 subtest 'Test Koha::Biblio::Volume::add_item & Koha::Biblio::Volume::items' => s Link Here
73
73
74
    my $volume = Koha::Biblio::Volume->new( { biblionumber => $biblio->id } )->store();
74
    my $volume = Koha::Biblio::Volume->new( { biblionumber => $biblio->id } )->store();
75
75
76
    my @items = $volume->items;
76
    my $items = $volume->items;
77
    is( scalar(@items), 0, 'Volume has no items');
77
    is( $items->count, 0, 'Volume has no items');
78
78
79
    $volume->add_item({ item_id => $item_1->id });
79
    $volume->add_item({ item_id => $item_1->id });
80
    @items = $volume->items->as_list;
80
    my @items = $volume->items->as_list;
81
    is( scalar(@items), 1, 'Volume has one item');
81
    is( scalar(@items), 1, 'Volume has one item');
82
    is( $items[0]->id, $item_1->id, 'Item 1 is correct' );
82
    is( $items[0]->id, $item_1->id, 'Item 1 is correct' );
83
83
Lines 117-123 subtest 'Test Koha::Item::volume' => sub { Link Here
117
117
118
subtest 'Koha::Item::delete should delete volume if no other items are using the volume' => sub {
118
subtest 'Koha::Item::delete should delete volume if no other items are using the volume' => sub {
119
119
120
    plan tests => 8;
120
    plan tests => 11;
121
121
122
    $schema->storage->txn_begin;
122
    $schema->storage->txn_begin;
123
123
Lines 137-147 subtest 'Koha::Item::delete should delete volume if no other items are using the Link Here
137
    my $volume = Koha::Biblio::Volumes->find( $volume_1->id );
137
    my $volume = Koha::Biblio::Volumes->find( $volume_1->id );
138
    is( $volume->id, $volume_1->id, 'Found the correct volume');
138
    is( $volume->id, $volume_1->id, 'Found the correct volume');
139
139
140
    is( $item_1->volume->id, $volume_1->id, 'Item 1 has correct volume');
141
    is( $item_2->volume->id, $volume_1->id, 'Item 2 has correct volume');
142
140
    $item_1->delete();
143
    $item_1->delete();
141
    is( $biblio->items->count, 1, 'Bib has 2 item');
144
    is( $biblio->items->count, 1, 'Bib has 2 item');
142
    $volume = Koha::Biblio::Volumes->find( $volume_1->id );
145
    $volume = Koha::Biblio::Volumes->find( $volume_1->id );
143
    is( $volume->id, $volume_1->id, 'Volume still exists after deleting and item, but other items remain');
146
    is( $volume->id, $volume_1->id, 'Volume still exists after deleting and item, but other items remain');
144
147
148
    is( $item_2->volume->id, $volume_1->id, 'Item 2 still has correct volume');
149
145
    $item_2->delete();
150
    $item_2->delete();
146
    is( $biblio->items->count, 0, 'Bib has 0 items');
151
    is( $biblio->items->count, 0, 'Bib has 0 items');
147
    $volume = Koha::Biblio::Volumes->find( $volume_1->id );
152
    $volume = Koha::Biblio::Volumes->find( $volume_1->id );
148
- 

Return to bug 24857