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 216-239 sub delete { Link Here
216
    # FIXME check the item has no current issues
216
    # FIXME check the item has no current issues
217
    # i.e. raise the appropriate exception
217
    # i.e. raise the appropriate exception
218
218
219
    # Get the volume so we can delete it later if it has no items left
220
    my $volume = C4::Context->preference('EnableVolumes') ? $self->volume : undef;
221
219
    my $result = $self->SUPER::delete;
222
    my $result = $self->SUPER::delete;
220
223
224
    # Delete the volume if it has no items left
225
    $volume->delete if ( $volume && $volume->items->count == 0 );
226
221
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
227
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
222
    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
228
    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
223
        unless $params->{skip_record_index};
229
        unless $params->{skip_record_index};
224
230
225
    if ( C4::Context->preference('EnableVolumes') ) {
226
        my $volume_item =
227
          Koha::Biblio::Volume::Items->find( { itemnumber => $self->itemnumber } );
228
        my $volume_id = $volume_item ? $volume_item->volume_id : undef;
229
230
        # If this item is the last item on a volume, delete the volume as well
231
        if ($volume_id) {
232
            my $volume = Koha::Biblio::Volumes->find($volume_id);
233
            $volume->delete unless $volume->items->count > 1;
234
        }
235
    }
236
237
    $self->_after_item_action_hooks({ action => 'delete' });
231
    $self->_after_item_action_hooks({ action => 'delete' });
238
232
239
    logaction( "CATALOGUING", "DELETE", $self->itemnumber, "item" )
233
    logaction( "CATALOGUING", "DELETE", $self->itemnumber, "item" )
Lines 416-422 sub volume { Link Here
416
    my $volume_rs = $volume_item->volume;
410
    my $volume_rs = $volume_item->volume;
417
    return unless $volume_rs;
411
    return unless $volume_rs;
418
412
419
    return Koha::Biblio::Volume->_new_from_dbic( $volume_rs );
413
    my $volume = Koha::Biblio::Volume->_new_from_dbic( $volume_rs );
414
    return $volume;
420
}
415
}
421
416
422
=head3 holds
417
=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