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

(-)a/C4/Items.pm (-29 / +16 lines)
Lines 156-193 names to values. If C<$serial> is true, include serial publication data. Link Here
156
sub GetItem {
156
sub GetItem {
157
    my ($itemnumber,$barcode, $serial) = @_;
157
    my ($itemnumber,$barcode, $serial) = @_;
158
    my $dbh = C4::Context->dbh;
158
    my $dbh = C4::Context->dbh;
159
	my $data;
160
159
160
    my $item;
161
    if ($itemnumber) {
161
    if ($itemnumber) {
162
        my $sth = $dbh->prepare("
162
        $item = Koha::Items->find( $itemnumber );
163
            SELECT * FROM items 
164
            WHERE itemnumber = ?");
165
        $sth->execute($itemnumber);
166
        $data = $sth->fetchrow_hashref;
167
    } else {
163
    } else {
168
        my $sth = $dbh->prepare("
164
        $item = Koha::Items->find( { barcode => $barcode } );
169
            SELECT * FROM items 
165
    }
170
            WHERE barcode = ?"
166
171
            );
167
    return unless ( $item );
172
        $sth->execute($barcode);		
168
173
        $data = $sth->fetchrow_hashref;
169
    my $data = $item->unblessed();
174
    }
170
    $data->{itype} = $item->effective_itemtype(); # set the correct itype
175
171
176
    return unless ( $data );
172
    if ($serial) {
177
173
        my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=?");
178
    if ( $serial) {      
174
        $ssth->execute( $data->{'itemnumber'} );
179
    my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=?");
175
        ( $data->{'serialseq'}, $data->{'publisheddate'} ) = $ssth->fetchrow_array();
180
        $ssth->execute($data->{'itemnumber'}) ;
176
    }
181
        ($data->{'serialseq'} , $data->{'publisheddate'}) = $ssth->fetchrow_array();
177
182
    }
183
	#if we don't have an items.itype, use biblioitems.itemtype.
184
    # FIXME this should respect the itypes systempreference
185
    # if (C4::Context->preference('item-level_itypes')) {
186
	if( ! $data->{'itype'} ) {
187
		my $sth = $dbh->prepare("SELECT itemtype FROM biblioitems  WHERE biblionumber = ?");
188
		$sth->execute($data->{'biblionumber'});
189
		($data->{'itype'}) = $sth->fetchrow_array;
190
	}
191
    return $data;
178
    return $data;
192
}    # sub GetItem
179
}    # sub GetItem
193
180
(-)a/t/db_dependent/Items.t (-21 / +64 lines)
Lines 40-46 my $location = 'My Location'; Link Here
40
40
41
subtest 'General Add, Get and Del tests' => sub {
41
subtest 'General Add, Get and Del tests' => sub {
42
42
43
    plan tests => 14;
43
    plan tests => 16;
44
44
45
    $schema->storage->txn_begin;
45
    $schema->storage->txn_begin;
46
46
Lines 48-60 subtest 'General Add, Get and Del tests' => sub { Link Here
48
    my $library = $builder->build({
48
    my $library = $builder->build({
49
        source => 'Branch',
49
        source => 'Branch',
50
    });
50
    });
51
    my $itemtype = $builder->build({
52
        source => 'Itemtype',
53
    });
51
54
52
    # Create a biblio instance for testing
55
    # Create a biblio instance for testing
53
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
56
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
54
    my ($bibnum, $bibitemnum) = get_biblio();
57
    my ($bibnum, $bibitemnum) = get_biblio();
55
58
56
    # Add an item.
59
    # Add an item.
57
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location } , $bibnum);
60
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
58
    cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
61
    cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
59
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
62
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
60
63
Lines 75-81 subtest 'General Add, Get and Del tests' => sub { Link Here
75
    my $getdeleted = GetItem($itemnumber);
78
    my $getdeleted = GetItem($itemnumber);
76
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
79
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
77
80
78
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location' } , $bibnum);
81
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum);
79
    $getitem = GetItem($itemnumber);
82
    $getitem = GetItem($itemnumber);
80
    is( $getitem->{location}, $location, "The location should not have been modified" );
83
    is( $getitem->{location}, $location, "The location should not have been modified" );
81
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
84
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
Lines 90-95 subtest 'General Add, Get and Del tests' => sub { Link Here
90
    is( $getitem->{location}, 'CART', "The location should have been set to CART" );
93
    is( $getitem->{location}, 'CART', "The location should have been set to CART" );
91
    is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
94
    is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
92
95
96
    C4::Context->set_preference('item-level_itypes', '1');
97
    $getitem = GetItem($itemnumber);
98
    is( $getitem->{itype}, $itemtype->{itemtype}, "Itemtype set correctly when using item_level-itypes" );
99
    C4::Context->set_preference('item-level_itypes', '0');
100
    $getitem = GetItem($itemnumber);
101
    is( $getitem->{itype}, undef, "Itemtype set correctly when not using item_level-itypes" );
102
93
    $schema->storage->txn_rollback;
103
    $schema->storage->txn_rollback;
94
};
104
};
95
105
Lines 109-131 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
109
    my $library2 = $builder->build({
119
    my $library2 = $builder->build({
110
        source => 'Branch',
120
        source => 'Branch',
111
    });
121
    });
122
    my $itemtype = $builder->build({
123
        source => 'Itemtype',
124
    });
112
125
113
    # Create a new biblio
126
    # Create a new biblio
114
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
127
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
115
    my ($biblionumber, $biblioitemnumber) = get_biblio();
128
    my ($biblionumber, $biblioitemnumber) = get_biblio();
116
129
117
    # Add two items
130
    # Add two items
118
    my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem(
131
    my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem(
119
            { homebranch => $library1->{branchcode},
132
        {
120
              holdingbranch => $library1->{branchcode},
133
            homebranch    => $library1->{branchcode},
121
              withdrawn => 1 },
134
            holdingbranch => $library1->{branchcode},
122
            $biblionumber
135
            withdrawn     => 1,
136
            itype         => $itemtype->{itemtype},
137
        },
138
        $biblionumber
123
    );
139
    );
124
    my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem(
140
    my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem(
125
            { homebranch => $library2->{branchcode},
141
        {
126
              holdingbranch => $library2->{branchcode},
142
            homebranch    => $library2->{branchcode},
127
              withdrawn => 0 },
143
            holdingbranch => $library2->{branchcode},
128
            $biblionumber
144
            withdrawn     => 0,
145
            itype         => $itemtype->{itemtype},
146
        },
147
        $biblionumber
129
    );
148
    );
130
149
131
    my $opachiddenitems;
150
    my $opachiddenitems;
Lines 192-206 subtest 'GetItemsInfo tests' => sub { Link Here
192
    my $library2 = $builder->build({
211
    my $library2 = $builder->build({
193
        source => 'Branch',
212
        source => 'Branch',
194
    });
213
    });
214
    my $itemtype = $builder->build({
215
        source => 'Itemtype',
216
    });
195
217
196
    # Add a biblio
218
    # Add a biblio
197
    my ($biblionumber, $biblioitemnumber) = get_biblio();
219
    my ($biblionumber, $biblioitemnumber) = get_biblio();
198
    # Add an item
220
    # Add an item
199
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
221
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
200
        = AddItem({
222
        {
201
                homebranch    => $library1->{branchcode},
223
            homebranch    => $library1->{branchcode},
202
                holdingbranch => $library2->{branchcode},
224
            holdingbranch => $library2->{branchcode},
203
            }, $biblionumber );
225
            itype         => $itemtype->{itemtype},
226
        },
227
        $biblionumber
228
    );
204
229
205
    my $library = Koha::Libraries->find( $library1->{branchcode} );
230
    my $library = Koha::Libraries->find( $library1->{branchcode} );
206
    $library->opac_info("homebranch OPAC info");
231
    $library->opac_info("homebranch OPAC info");
Lines 274-279 subtest 'SearchItems test' => sub { Link Here
274
    my $library2 = $builder->build({
299
    my $library2 = $builder->build({
275
        source => 'Branch',
300
        source => 'Branch',
276
    });
301
    });
302
    my $itemtype = $builder->build({
303
        source => 'Itemtype',
304
    });
277
305
278
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
306
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
279
    my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
307
    my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
Lines 286-295 subtest 'SearchItems test' => sub { Link Here
286
    my (undef, undef, $item1_itemnumber) = AddItem({
314
    my (undef, undef, $item1_itemnumber) = AddItem({
287
        homebranch => $library1->{branchcode},
315
        homebranch => $library1->{branchcode},
288
        holdingbranch => $library1->{branchcode},
316
        holdingbranch => $library1->{branchcode},
317
        itype => $itemtype->{itemtype},
289
    }, $biblionumber);
318
    }, $biblionumber);
290
    my (undef, undef, $item2_itemnumber) = AddItem({
319
    my (undef, undef, $item2_itemnumber) = AddItem({
291
        homebranch => $library2->{branchcode},
320
        homebranch => $library2->{branchcode},
292
        holdingbranch => $library2->{branchcode},
321
        holdingbranch => $library2->{branchcode},
322
        itype => $itemtype->{itemtype},
293
    }, $biblionumber);
323
    }, $biblionumber);
294
324
295
    my ($items, $total_results);
325
    my ($items, $total_results);
Lines 443-453 subtest 'Koha::Item(s) tests' => sub { Link Here
443
    my $library2 = $builder->build({
473
    my $library2 = $builder->build({
444
        source => 'Branch',
474
        source => 'Branch',
445
    });
475
    });
476
    my $itemtype = $builder->build({
477
        source => 'Itemtype',
478
    });
446
479
447
    # Create a biblio and item for testing
480
    # Create a biblio and item for testing
448
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
481
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
449
    my ($bibnum, $bibitemnum) = get_biblio();
482
    my ($bibnum, $bibitemnum) = get_biblio();
450
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} } , $bibnum);
483
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
484
        {
485
            homebranch    => $library1->{branchcode},
486
            holdingbranch => $library2->{branchcode},
487
            itype         => $itemtype->{itemtype},
488
        },
489
        $bibnum
490
    );
451
491
452
    # Get item.
492
    # Get item.
453
    my $item = Koha::Items->find( $itemnumber );
493
    my $item = Koha::Items->find( $itemnumber );
Lines 476-481 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
476
    my $library2 = $builder->build({
516
    my $library2 = $builder->build({
477
        source => 'Branch',
517
        source => 'Branch',
478
    });
518
    });
519
    my $itemtype = $builder->build({
520
        source => 'Itemtype',
521
    });
479
522
480
    my ( $biblionumber, $biblioitemnumber ) = get_biblio();
523
    my ( $biblionumber, $biblioitemnumber ) = get_biblio();
481
    my $item_infos = [
524
    my $item_infos = [
Lines 497-503 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
497
        my ( undef, undef, $itemnumber ) = AddItem(
540
        my ( undef, undef, $itemnumber ) = AddItem(
498
            {
541
            {
499
                homebranch    => $item_info->{homebranch},
542
                homebranch    => $item_info->{homebranch},
500
                holdingbranch => $item_info->{holdingbanch}
543
                holdingbranch => $item_info->{holdingbanch},
544
                itype         => $itemtype->{itemtype},
501
            },
545
            },
502
            $biblionumber
546
            $biblionumber
503
        );
547
        );
504
- 

Return to bug 14598