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

(-)a/Koha/Biblio.pm (+16 lines)
Lines 34-39 use base qw(Koha::Object); Link Here
34
use Koha::Acquisition::Orders;
34
use Koha::Acquisition::Orders;
35
use Koha::ArticleRequests;
35
use Koha::ArticleRequests;
36
use Koha::Biblio::Metadatas;
36
use Koha::Biblio::Metadatas;
37
use Koha::Biblio::ItemGroups;
37
use Koha::Biblioitems;
38
use Koha::Biblioitems;
38
use Koha::Checkouts;
39
use Koha::Checkouts;
39
use Koha::CirculationRules;
40
use Koha::CirculationRules;
Lines 117-122 sub active_orders { Link Here
117
    return $self->orders->search({ datecancellationprinted => undef });
118
    return $self->orders->search({ datecancellationprinted => undef });
118
}
119
}
119
120
121
=head3 item_groups
122
123
my $item_groups = $biblio->item_groups();
124
125
Returns a Koha::Biblio::ItemGroups object
126
127
=cut
128
129
sub item_groups {
130
    my ( $self ) = @_;
131
132
    my $item_groups = $self->_result->item_groups;
133
    return Koha::Biblio::ItemGroups->_new_from_dbic($item_groups);
134
}
135
120
=head3 can_article_request
136
=head3 can_article_request
121
137
122
my $bool = $biblio->can_article_request( $borrower );
138
my $bool = $biblio->can_article_request( $borrower );
(-)a/Koha/Item.pm (+22 lines)
Lines 30-35 use C4::Reserves; Link Here
30
use C4::ClassSource qw( GetClassSort );
30
use C4::ClassSource qw( GetClassSort );
31
use C4::Log qw( logaction );
31
use C4::Log qw( logaction );
32
32
33
use Koha::Biblio::ItemGroups;
33
use Koha::Checkouts;
34
use Koha::Checkouts;
34
use Koha::CirculationRules;
35
use Koha::CirculationRules;
35
use Koha::CoverImages;
36
use Koha::CoverImages;
Lines 403-408 sub checkout { Link Here
403
    return Koha::Checkout->_new_from_dbic( $checkout_rs );
404
    return Koha::Checkout->_new_from_dbic( $checkout_rs );
404
}
405
}
405
406
407
=head3 item_group
408
409
my $item_group = $item->item_group;
410
411
Return the item group for this item
412
413
=cut
414
415
sub item_group {
416
    my ( $self ) = @_;
417
418
    my $item_group_item = $self->_result->item_group_item;
419
    return unless $item_group_item;
420
421
    my $item_group_rs = $item_group_item->item_group;
422
    return unless $item_group_rs;
423
424
    my $item_group = Koha::Biblio::ItemGroup->_new_from_dbic( $item_group_rs );
425
    return $item_group;
426
}
427
406
=head3 holds
428
=head3 holds
407
429
408
my $holds = $item->holds();
430
my $holds = $item->holds();
(-)a/t/db_dependent/Koha/Biblio.t (-1 / +28 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 20;
20
use Test::More tests => 21;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
Lines 884-889 subtest 'get_marc_authors() tests' => sub { Link Here
884
    $schema->storage->txn_rollback;
884
    $schema->storage->txn_rollback;
885
};
885
};
886
886
887
subtest 'item_groups() tests' => sub {
888
889
    plan tests => 6;
890
891
    $schema->storage->txn_begin;
892
893
    my $biblio = $builder->build_sample_biblio();
894
895
    my @item_groups = $biblio->item_groups->as_list;
896
    is( scalar(@item_groups), 0, 'Got zero item groups');
897
898
    my $item_group_1 = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
899
900
    @item_groups = $biblio->item_groups->as_list;
901
    is( scalar(@item_groups), 1, 'Got one item group');
902
    is( $item_groups[0]->id, $item_group_1->id, 'Got correct item group');
903
904
    my $item_group_2 = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
905
906
    @item_groups = $biblio->item_groups->as_list;
907
    is( scalar(@item_groups), 2, 'Got two item groups');
908
    is( $item_groups[0]->id, $item_group_1->id, 'Got correct item group 1');
909
    is( $item_groups[1]->id, $item_group_2->id, 'Got correct item group 2');
910
911
    $schema->storage->txn_rollback;
912
};
913
887
sub component_record1 {
914
sub component_record1 {
888
    my $marc = MARC::Record->new;
915
    my $marc = MARC::Record->new;
889
    $marc->append_fields(
916
    $marc->append_fields(
(-)a/t/db_dependent/Koha/Item.t (-2 / +26 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
use utf8;
21
use utf8;
22
22
23
use Test::More tests => 14;
23
use Test::More tests => 15;
24
use Test::Exception;
24
use Test::Exception;
25
25
26
use C4::Biblio qw( GetMarcSubfieldStructure );
26
use C4::Biblio qw( GetMarcSubfieldStructure );
Lines 1224-1226 subtest 'store() tests' => sub { Link Here
1224
        $schema->storage->txn_rollback;
1224
        $schema->storage->txn_rollback;
1225
    };
1225
    };
1226
};
1226
};
1227
- 
1227
1228
subtest 'item_group() tests' => sub {
1229
1230
    plan tests => 4;
1231
1232
    $schema->storage->txn_begin;
1233
1234
    my $biblio = $builder->build_sample_biblio();
1235
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
1236
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
1237
1238
    is( $item_1->item_group, undef, 'Item 1 has no item group');
1239
    is( $item_2->item_group, undef, 'Item 2 has no item group');
1240
1241
    my $item_group_1 = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
1242
    my $item_group_2 = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
1243
1244
    $item_group_1->add_item({ item_id => $item_1->id });
1245
    $item_group_2->add_item({ item_id => $item_2->id });
1246
1247
    is( $item_1->item_group->id, $item_group_1->id, 'Got item group 1 correctly' );
1248
    is( $item_2->item_group->id, $item_group_2->id, 'Got item group 2 correctly' );
1249
1250
    $schema->storage->txn_rollback;
1251
};

Return to bug 24857